We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7fec841 commit 54a8d69Copy full SHA for 54a8d69
src/libcore/str.rs
@@ -671,18 +671,18 @@ Section: Comparing strings
671
672
/// Bytewise slice equality
673
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;
+ 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
+ }
683
684
685
}
- return true;
686
687
688
/// Bytewise string equality
0 commit comments