Skip to content

Commit 54a8d69

Browse files
committed
Change str : Eq to use memcmp.
1 parent 7fec841 commit 54a8d69

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Diff for: src/libcore/str.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -671,18 +671,18 @@ Section: Comparing strings
671671

672672
/// Bytewise slice equality
673673
pure fn eq_slice(a: &str, b: &str) -> bool {
674-
let a_len = a.len();
675-
let b_len = b.len();
676-
if a_len != b_len { return false; }
677-
let mut end = uint::min(&a_len, &b_len);
678-
679-
let mut i = 0u;
680-
while i < end {
681-
if a[i] != b[i] { return false; }
682-
i += 1u;
674+
do as_buf(a) |ap, alen| {
675+
do as_buf(b) |bp, blen| {
676+
if (alen != blen) { false }
677+
else {
678+
unsafe {
679+
libc::memcmp(ap as *libc::c_void,
680+
bp as *libc::c_void,
681+
alen as libc::size_t) == 0
682+
}
683+
}
684+
}
683685
}
684-
685-
return true;
686686
}
687687

688688
/// Bytewise string equality

0 commit comments

Comments
 (0)