about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2012-08-30 16:27:06 -0700
committerGraydon Hoare <graydon@mozilla.com>2012-08-30 16:27:31 -0700
commit54a8d69c4feb878e0367cc55772c04ee2d59c8a5 (patch)
treef3a709bc9aa682451e9ee0f5258a2a4279431a58 /src
parent7fec8419f38bbcd662b24cc7b4a77a902150e3db (diff)
Change str : Eq to use memcmp.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/str.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index a2e29afa3aa..7e13e75a93d 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -671,18 +671,18 @@ Section: Comparing strings
 
 /// Bytewise slice equality
 pure fn eq_slice(a: &str, b: &str) -> bool {
-    let a_len = a.len();
-    let b_len = b.len();
-    if a_len != b_len { return false; }
-    let mut end = uint::min(&a_len, &b_len);
-
-    let mut i = 0u;
-    while i < end {
-        if a[i] != b[i] { return false; }
-        i += 1u;
+    do as_buf(a) |ap, alen| {
+        do as_buf(b) |bp, blen| {
+            if (alen != blen) { false }
+            else {
+                unsafe {
+                    libc::memcmp(ap as *libc::c_void,
+                                 bp as *libc::c_void,
+                                 alen as libc::size_t) == 0
+                }
+            }
+        }
     }
-
-    return true;
 }
 
 /// Bytewise string equality