diff options
| author | Kevin Cantu <me@kevincantu.org> | 2012-02-12 17:33:45 -0800 |
|---|---|---|
| committer | Kevin Cantu <me@kevincantu.org> | 2012-02-13 01:56:10 -0800 |
| commit | 0e61fe2eeaff507ed409c432988aed40a9fe9c63 (patch) | |
| tree | 9c9c978ab7c84978318ad796fe1e1c095bf223d9 | |
| parent | 8309d50ff4ead4dd58b8f3c8388d5668e2e0d152 (diff) | |
| download | rust-0e61fe2eeaff507ed409c432988aed40a9fe9c63.tar.gz rust-0e61fe2eeaff507ed409c432988aed40a9fe9c63.zip | |
(core::str) use slice_bytes in starts_with for a little bit less string traversal
| -rw-r--r-- | src/libcore/str.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 5d39fb72b7e..8baec57725d 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -932,12 +932,12 @@ Parameters: haystack - The string to look in needle - The string to look for */ -fn starts_with(haystack: str, needle: str) -> bool { - let haystack_len: uint = len(haystack); - let needle_len: uint = len(needle); +fn starts_with(haystack: str, needle: str) -> bool unsafe { + let haystack_len: uint = len_bytes(haystack); + let needle_len: uint = len_bytes(needle); if needle_len == 0u { ret true; } if needle_len > haystack_len { ret false; } - ret eq(substr(haystack, 0u, needle_len), needle); + ret eq(unsafe::slice_bytes(haystack, 0u, needle_len), needle); } /* |
