diff options
| author | Brian Anderson <[email protected]> | 2011-05-11 00:05:03 -0400 |
|---|---|---|
| committer | Brian Anderson <[email protected]> | 2011-05-11 01:38:16 -0400 |
| commit | e35984b6c67f2adf1c12d84c48fdf4f01be020e5 (patch) | |
| tree | 73ee96cb57bcb696357ccc9252b2dd499905131e /src/lib | |
| parent | More alias-ification of trans. (diff) | |
| download | rust-e35984b6c67f2adf1c12d84c48fdf4f01be020e5.tar.xz 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/lib')
| -rw-r--r-- | src/lib/Str.rs | 12 |
1 files changed, 5 insertions, 7 deletions
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 { |