about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorUlrik Sverdrup <bluss@users.noreply.github.com>2015-07-04 15:10:20 +0200
committerUlrik Sverdrup <bluss@users.noreply.github.com>2015-07-04 15:10:20 +0200
commit0da69969d1fc8d375867ff07dfcefa2c4a2e7724 (patch)
treeaacf2950c6219f6500cba652658a387432fb84c6 /src/libcore
parent0dc08240ea755679e3daec3832a04b22a8fc90bf (diff)
downloadrust-0da69969d1fc8d375867ff07dfcefa2c4a2e7724.tar.gz
rust-0da69969d1fc8d375867ff07dfcefa2c4a2e7724.zip
core: Use memcmp in is_prefix_of / is_suffix_of
The basic str equality in core::str calls memcmp, re-use the same
function in StrSearcher's is_prefix_of, is_suffix_of.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/str/pattern.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs
index dccdaa9120d..707f7fcf2ab 100644
--- a/src/libcore/str/pattern.rs
+++ b/src/libcore/str/pattern.rs
@@ -513,17 +513,16 @@ impl<'a, 'b> Pattern<'a> for &'b str {
     /// Checks whether the pattern matches at the front of the haystack
     #[inline]
     fn is_prefix_of(self, haystack: &'a str) -> bool {
-        // Use `as_bytes` so that we can slice through a character in the haystack.
-        // Since self is always valid UTF-8, this can't result in a false positive.
-        self.len() <= haystack.len() &&
-            self.as_bytes() == &haystack.as_bytes()[..self.len()]
+        haystack.is_char_boundary(self.len()) &&
+            self == &haystack[..self.len()]
     }
 
     /// Checks whether the pattern matches at the back of the haystack
     #[inline]
     fn is_suffix_of(self, haystack: &'a str) -> bool {
         self.len() <= haystack.len() &&
-            self.as_bytes() == &haystack.as_bytes()[haystack.len() - self.len()..]
+            haystack.is_char_boundary(haystack.len() - self.len()) &&
+            self == &haystack[haystack.len() - self.len()..]
     }
 }