diff options
| author | bors <bors@rust-lang.org> | 2019-12-16 18:55:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-12-16 18:55:07 +0000 |
| commit | 99b89533d4cdf7682ea4054ad0ee36c351d05df1 (patch) | |
| tree | 82ce6096679ca921b3eb76f24cf8480ecfc77802 /src/libcore/str/pattern.rs | |
| parent | f0d4b571936d4072ed90ab7750636f68f1443b3e (diff) | |
| parent | 733559b0c292cfa3fd6e4afffd820fa903ea320a (diff) | |
| download | rust-99b89533d4cdf7682ea4054ad0ee36c351d05df1.tar.gz rust-99b89533d4cdf7682ea4054ad0ee36c351d05df1.zip | |
Auto merge of #67356 - Centril:rollup-paaw3ju, r=Centril
Rollup of 8 pull requests Successful merges: - #67249 (Improve code generated for `starts_with(<literal char>)`) - #67308 (Delete flaky test net::tcp::tests::fast_rebind) - #67318 (Improve typeck & lowering docs for slice patterns) - #67322 (use Self alias in place of macros) - #67323 (make transparent enums more ordinary) - #67336 (Fix JS error when loading page with search) - #67344 (.gitignore: Don't ignore a file that exists in the repository) - #67349 (Minor: update Unsize docs for dyn syntax) Failed merges: r? @ghost
Diffstat (limited to 'src/libcore/str/pattern.rs')
| -rw-r--r-- | src/libcore/str/pattern.rs | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 1037da14b5f..b7ebd5f88b5 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -445,21 +445,13 @@ impl<'a> Pattern<'a> for char { #[inline] fn is_prefix_of(self, haystack: &'a str) -> bool { - if let Some(ch) = haystack.chars().next() { - self == ch - } else { - false - } + self.encode_utf8(&mut [0u8; 4]).is_prefix_of(haystack) } #[inline] fn is_suffix_of(self, haystack: &'a str) -> bool where Self::Searcher: ReverseSearcher<'a> { - if let Some(ch) = haystack.chars().next_back() { - self == ch - } else { - false - } + self.encode_utf8(&mut [0u8; 4]).is_suffix_of(haystack) } } @@ -710,16 +702,13 @@ 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 { - haystack.is_char_boundary(self.len()) && - self == &haystack[..self.len()] + haystack.as_bytes().starts_with(self.as_bytes()) } /// 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() && - haystack.is_char_boundary(haystack.len() - self.len()) && - self == &haystack[haystack.len() - self.len()..] + haystack.as_bytes().ends_with(self.as_bytes()) } } |
