summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-06-08 17:38:12 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-06-08 17:38:12 -0700
commitfbd583bde2d51dadd87f1b3c74b4723399f7e3b9 (patch)
tree65fdf854e137a59cb059d2d363df6d3b20a83065 /src/libcore
parentc7c37debe4b7827234642df3c1ed378b7c3e1849 (diff)
downloadrust-fbd583bde2d51dadd87f1b3c74b4723399f7e3b9.tar.gz
rust-fbd583bde2d51dadd87f1b3c74b4723399f7e3b9.zip
core: Implement string equal natively to save a call into the shape code. Shaves a couple of seconds off rustc.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/str.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index 6c24b656988..1056e61fe27 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -595,7 +595,22 @@ Section: Comparing strings
 */
 
 #[doc = "Bytewise string equality"]
-pure fn eq(&&a: str, &&b: str) -> bool { a == b }
+pure fn eq(&&a: str, &&b: str) -> bool {
+    // FIXME: This should just be "a == b" but that calls into the shape code
+    // :(
+    let a_len = a.len();
+    let b_len = b.len();
+    if a_len != b_len { ret false; }
+    let mut end = uint::min(a_len, b_len);
+
+    let mut i = 0u;
+    while i < end {
+        if a[i] != b[i] { ret false; }
+        i += 1u;
+    }
+
+    ret true;
+}
 
 #[doc = "Bytewise less than or equal"]
 pure fn le(&&a: str, &&b: str) -> bool { a <= b }
@@ -1874,7 +1889,7 @@ impl extensions for str {
     fn is_alphanumeric() -> bool { is_alphanumeric(self) }
     #[inline]
     #[doc ="Returns the size in bytes not counting the null terminator"]
-    fn len() -> uint { len(self) }
+    pure fn len() -> uint { len(self) }
     #[doc = "
     Returns a slice of the given string from the byte range [`begin`..`end`)