about summary refs log tree commit diff
path: root/src/rt/rust_builtin.cpp
diff options
context:
space:
mode:
authorBrian Anderson <andersrb@gmail.com>2011-05-11 00:05:03 -0400
committerBrian Anderson <andersrb@gmail.com>2011-05-11 01:38:16 -0400
commite35984b6c67f2adf1c12d84c48fdf4f01be020e5 (patch)
tree73ee96cb57bcb696357ccc9252b2dd499905131e /src/rt/rust_builtin.cpp
parentdc0aab47a77fbd47354dc6cf64cdb300cb6fd4b3 (diff)
downloadrust-e35984b6c67f2adf1c12d84c48fdf4f01be020e5.tar.gz
rust-e35984b6c67f2adf1c12d84c48fdf4f01be020e5.zip
Introduce str_slice runtime function
This reduces the time to execute the new lib-str tests from 1:40ish to a few
seconds and will eventually allow the full lib-sha1 test to run in a
reasonable amount of time. XFAIL lib-str in stage0 - it will run very slowly
until the next snapshot.
Diffstat (limited to 'src/rt/rust_builtin.cpp')
-rw-r--r--src/rt/rust_builtin.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 297b9df7d95..bc2c5adde60 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -226,6 +226,24 @@ str_push_byte(rust_task* task, rust_str* v, size_t byte)
     return v;
 }
 
+extern "C" CDECL rust_str*
+str_slice(rust_task* task, rust_str* v, size_t begin, size_t end)
+{
+    size_t len = end - begin;
+    rust_str *st =
+        vec_alloc_with_data(task,
+                            len + 1, // +1 to fit at least '\0'
+                            len,
+                            1,
+                            len ? v->data + begin : NULL);
+    if (!st) {
+        task->fail(2);
+        return NULL;
+    }
+    st->data[st->fill++] = '\0';
+    return st;
+}
+
 extern "C" CDECL char const *
 str_buf(rust_task *task, rust_str *s)
 {