From e35984b6c67f2adf1c12d84c48fdf4f01be020e5 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 11 May 2011 00:05:03 -0400 Subject: 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. --- src/lib/Str.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Str.rs b/src/lib/Str.rs index ba0d45de..6e39b359 100644 --- a/src/lib/Str.rs +++ b/src/lib/Str.rs @@ -12,6 +12,7 @@ native "rust" mod rustrt { fn str_from_cstr(sbuf cstr) -> str; fn str_from_buf(sbuf buf, uint len) -> str; fn str_push_byte(str s, uint byte) -> str; + fn str_slice(str s, uint begin, uint end) -> str; fn refcount[T](str s) -> uint; } @@ -384,13 +385,10 @@ fn substr(str s, uint begin, uint len) -> str { } fn slice(str s, uint begin, uint end) -> str { - let str accum = ""; - let uint i = begin; - while (i < end) { - push_byte(accum, s.(i)); - i += 1u; - } - ret accum; + // FIXME: Typestate precondition + assert (begin <= end); + assert (end <= Str.byte_len(s)); + ret rustrt.str_slice(s, begin, end); } fn shift_byte(&mutable str s) -> u8 { -- cgit v1.2.3