Skip to content

Commit fbd583b

Browse files
committed
core: Implement string equal natively to save a call into the shape code. Shaves a couple of seconds off rustc.
1 parent c7c37de commit fbd583b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/libcore/str.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,22 @@ Section: Comparing strings
595595
*/
596596

597597
#[doc = "Bytewise string equality"]
598-
pure fn eq(&&a: str, &&b: str) -> bool { a == b }
598+
pure fn eq(&&a: str, &&b: str) -> bool {
599+
// FIXME: This should just be "a == b" but that calls into the shape code
600+
// :(
601+
let a_len = a.len();
602+
let b_len = b.len();
603+
if a_len != b_len { ret false; }
604+
let mut end = uint::min(a_len, b_len);
605+
606+
let mut i = 0u;
607+
while i < end {
608+
if a[i] != b[i] { ret false; }
609+
i += 1u;
610+
}
611+
612+
ret true;
613+
}
599614

600615
#[doc = "Bytewise less than or equal"]
601616
pure fn le(&&a: str, &&b: str) -> bool { a <= b }
@@ -1874,7 +1889,7 @@ impl extensions for str {
18741889
fn is_alphanumeric() -> bool { is_alphanumeric(self) }
18751890
#[inline]
18761891
#[doc ="Returns the size in bytes not counting the null terminator"]
1877-
fn len() -> uint { len(self) }
1892+
pure fn len() -> uint { len(self) }
18781893
#[doc = "
18791894
Returns a slice of the given string from the byte range [`begin`..`end`)
18801895

0 commit comments

Comments
 (0)