diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-08-30 16:27:06 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-08-30 16:27:31 -0700 |
| commit | 54a8d69c4feb878e0367cc55772c04ee2d59c8a5 (patch) | |
| tree | f3a709bc9aa682451e9ee0f5258a2a4279431a58 /src | |
| parent | 7fec8419f38bbcd662b24cc7b4a77a902150e3db (diff) | |
Change str : Eq to use memcmp.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/str.rs | 22 |
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 |
