]> git.lizzy.rs Git - rust.git/commitdiff
StrSearcher: Explicitly separate the long and short cases
authorUlrik Sverdrup <root@localhost>
Wed, 24 Jun 2015 14:22:09 +0000 (16:22 +0200)
committerUlrik Sverdrup <root@localhost>
Wed, 24 Jun 2015 14:22:09 +0000 (16:22 +0200)
This is needed to not drop performance, after the trait-based changes.
Force separate versions of the next method to be generated for the short
and long period cases.

src/libcore/str/pattern.rs

index 6d68615a8cfd73ebb9b8328d09dec3cbef8ded78..dccdaa9120d10146c8171e999e9b4e81e932c656 100644 (file)
@@ -628,7 +628,7 @@ fn next(&mut self) -> SearchStep {
         }
     }
 
-    #[inline]
+    #[inline(always)]
     fn next_match(&mut self) -> Option<(usize, usize)> {
         match self.searcher {
             StrSearcherImpl::Empty(..) => {
@@ -642,9 +642,15 @@ fn next_match(&mut self) -> Option<(usize, usize)> {
             }
             StrSearcherImpl::TwoWay(ref mut searcher) => {
                 let is_long = searcher.memory == usize::MAX;
-                searcher.next::<MatchOnly>(self.haystack.as_bytes(),
-                                           self.needle.as_bytes(),
-                                           is_long)
+                if is_long {
+                    searcher.next::<MatchOnly>(self.haystack.as_bytes(),
+                                               self.needle.as_bytes(),
+                                               true)
+                } else {
+                    searcher.next::<MatchOnly>(self.haystack.as_bytes(),
+                                               self.needle.as_bytes(),
+                                               false)
+                }
             }
         }
     }
@@ -854,7 +860,7 @@ fn byteset_contains(&self, byte: u8) -> bool {
     // left to right. If v matches, we try to match u by scanning right to left.
     // How far we can jump when we encounter a mismatch is all based on the fact
     // that (u, v) is a critical factorization for the needle.
-    #[inline]
+    #[inline(always)]
     fn next<S>(&mut self, haystack: &[u8], needle: &[u8], long_period: bool)
         -> S::Output
         where S: TwoWayStrategy