]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/str/pattern.rs
Auto merge of #43710 - zackmdavis:field_init_shorthand_power_slam, r=Mark-Simulacrum
[rust.git] / src / libcore / str / pattern.rs
index 4918e37eb35f08a266122920a2def0a07bb2ea81..edb7bed4520fb0e1df9f5635cc96a6eebc1078ff 100644 (file)
@@ -83,7 +83,7 @@ pub enum SearchStep {
     /// Note that there might be more than one `Reject` between two `Match`es,
     /// there is no requirement for them to be combined into one.
     Reject(usize, usize),
-    /// Expresses that every byte of the haystack has been visted, ending
+    /// Expresses that every byte of the haystack has been visited, ending
     /// the iteration.
     Done
 }
@@ -101,7 +101,7 @@ pub enum SearchStep {
 /// the haystack. This enables consumers of this trait to
 /// slice the haystack without additional runtime checks.
 pub unsafe trait Searcher<'a> {
-    /// Getter for the underlaying string to be searched in
+    /// Getter for the underlying string to be searched in
     ///
     /// Will always return the same `&str`
     fn haystack(&self) -> &'a str;
@@ -290,7 +290,7 @@ impl<'a, C: CharEq> Pattern<'a> for CharEqPattern<C> {
     fn into_searcher(self, haystack: &'a str) -> CharEqSearcher<'a, C> {
         CharEqSearcher {
             ascii_only: self.0.only_ascii(),
-            haystack: haystack,
+            haystack,
             char_eq: self.0,
             char_indices: haystack.char_indices(),
         }
@@ -596,8 +596,8 @@ impl<'a, 'b> StrSearcher<'a, 'b> {
     fn new(haystack: &'a str, needle: &'b str) -> StrSearcher<'a, 'b> {
         if needle.is_empty() {
             StrSearcher {
-                haystack: haystack,
-                needle: needle,
+                haystack,
+                needle,
                 searcher: StrSearcherImpl::Empty(EmptyNeedle {
                     position: 0,
                     end: haystack.len(),
@@ -607,8 +607,8 @@ fn new(haystack: &'a str, needle: &'b str) -> StrSearcher<'a, 'b> {
             }
         } else {
             StrSearcher {
-                haystack: haystack,
-                needle: needle,
+                haystack,
+                needle,
                 searcher: StrSearcherImpl::TwoWay(
                     TwoWaySearcher::new(needle.as_bytes(), haystack.len())
                 ),
@@ -618,7 +618,10 @@ fn new(haystack: &'a str, needle: &'b str) -> StrSearcher<'a, 'b> {
 }
 
 unsafe impl<'a, 'b> Searcher<'a> for StrSearcher<'a, 'b> {
-    fn haystack(&self) -> &'a str { self.haystack }
+    #[inline]
+    fn haystack(&self) -> &'a str {
+        self.haystack
+    }
 
     #[inline]
     fn next(&mut self) -> SearchStep {
@@ -665,7 +668,7 @@ fn next(&mut self) -> SearchStep {
         }
     }
 
-    #[inline(always)]
+    #[inline]
     fn next_match(&mut self) -> Option<(usize, usize)> {
         match self.searcher {
             StrSearcherImpl::Empty(..) => {
@@ -896,13 +899,13 @@ fn new(needle: &[u8], end: usize) -> TwoWaySearcher {
                 TwoWaySearcher::reverse_maximal_suffix(needle, period, true));
 
             TwoWaySearcher {
-                crit_pos: crit_pos,
-                crit_pos_back: crit_pos_back,
-                period: period,
+                crit_pos,
+                crit_pos_back,
+                period,
                 byteset: Self::byteset_create(&needle[..period]),
 
                 position: 0,
-                end: end,
+                end,
                 memory: 0,
                 memory_back: needle.len(),
             }
@@ -915,13 +918,13 @@ fn new(needle: &[u8], end: usize) -> TwoWaySearcher {
             // reverse search.
 
             TwoWaySearcher {
-                crit_pos: crit_pos,
+                crit_pos,
                 crit_pos_back: crit_pos,
                 period: cmp::max(crit_pos, needle.len() - crit_pos) + 1,
                 byteset: Self::byteset_create(needle),
 
                 position: 0,
-                end: end,
+                end,
                 memory: usize::MAX, // Dummy value to signify that the period is long
                 memory_back: usize::MAX,
             }
@@ -933,7 +936,7 @@ fn byteset_create(bytes: &[u8]) -> u64 {
         bytes.iter().fold(0, |a, &b| (1 << (b & 0x3f)) | a)
     }
 
-    #[inline(always)]
+    #[inline]
     fn byteset_contains(&self, byte: u8) -> bool {
         (self.byteset >> ((byte & 0x3f) as usize)) & 1 != 0
     }
@@ -943,7 +946,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(always)]
+    #[inline]
     fn next<S>(&mut self, haystack: &[u8], needle: &[u8], long_period: bool)
         -> S::Output
         where S: TwoWayStrategy
@@ -1150,7 +1153,7 @@ fn maximal_suffix(arr: &[u8], order_greater: bool) -> (usize, usize) {
     // The maximal suffix is a possible critical factorization (u', v') of `arr`.
     //
     // Returns `i` where `i` is the starting index of v', from the back;
-    // returns immedately when a period of `known_period` is reached.
+    // returns immediately when a period of `known_period` is reached.
     //
     // `order_greater` determines if lexical order is `<` or `>`. Both
     // orders must be computed -- the ordering with the largest `i` gives