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.
This commit is contained in:
Brian Anderson
2011-05-11 00:05:03 -04:00
parent dc0aab47a7
commit e35984b6c6
4 changed files with 58 additions and 7 deletions

View File

@@ -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)
{