(core::str) use slice_bytes in starts_with for a little bit less string traversal
This commit is contained in:
parent
8309d50ff4
commit
0e61fe2eea
1 changed files with 4 additions and 4 deletions
|
@ -932,12 +932,12 @@ Parameters:
|
||||||
haystack - The string to look in
|
haystack - The string to look in
|
||||||
needle - The string to look for
|
needle - The string to look for
|
||||||
*/
|
*/
|
||||||
fn starts_with(haystack: str, needle: str) -> bool {
|
fn starts_with(haystack: str, needle: str) -> bool unsafe {
|
||||||
let haystack_len: uint = len(haystack);
|
let haystack_len: uint = len_bytes(haystack);
|
||||||
let needle_len: uint = len(needle);
|
let needle_len: uint = len_bytes(needle);
|
||||||
if needle_len == 0u { ret true; }
|
if needle_len == 0u { ret true; }
|
||||||
if needle_len > haystack_len { ret false; }
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue