diff options
| author | bors <bors@rust-lang.org> | 2025-03-16 14:23:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-16 14:23:18 +0000 |
| commit | 8b87fefd76665236a304d3c0998e1021710ce1b0 (patch) | |
| tree | 7d2afc19652a16217a94d018bf39221f8d261bdc | |
| parent | d497e43a1664eaad5e5850f5f8c11c9e16f5ef66 (diff) | |
| parent | bfe536342f3bfaacea11ad4957e541d4219ae4ea (diff) | |
| download | rust-8b87fefd76665236a304d3c0998e1021710ce1b0.tar.gz rust-8b87fefd76665236a304d3c0998e1021710ce1b0.zip | |
Auto merge of #138537 - yotamofek:pr/lib/multi-char-pattern, r=jhpratt
Optimize multi-char string patterns Uses specialization for `[T]::contains` from #130991 to optimize multi-char patterns in string searches. Requesting a perf run to see if this actually has an effect 🙏 (I think that adding `char` to the list of types for which the `SliceContains` is specialized is a good idea, even if it doesn't show up on perf - might be helpful for downstream users)
| -rw-r--r-- | library/core/src/slice/cmp.rs | 2 | ||||
| -rw-r--r-- | library/core/src/str/pattern.rs | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/library/core/src/slice/cmp.rs b/library/core/src/slice/cmp.rs index 804bdfcbb4f..da85f42926e 100644 --- a/library/core/src/slice/cmp.rs +++ b/library/core/src/slice/cmp.rs @@ -282,4 +282,4 @@ macro_rules! impl_slice_contains { }; } -impl_slice_contains!(u16, u32, u64, i16, i32, i64, f32, f64, usize, isize); +impl_slice_contains!(u16, u32, u64, i16, i32, i64, f32, f64, usize, isize, char); diff --git a/library/core/src/str/pattern.rs b/library/core/src/str/pattern.rs index 2d941adfd85..bcbbb11c83b 100644 --- a/library/core/src/str/pattern.rs +++ b/library/core/src/str/pattern.rs @@ -644,21 +644,21 @@ where impl<const N: usize> MultiCharEq for [char; N] { #[inline] fn matches(&mut self, c: char) -> bool { - self.iter().any(|&m| m == c) + self.contains(&c) } } impl<const N: usize> MultiCharEq for &[char; N] { #[inline] fn matches(&mut self, c: char) -> bool { - self.iter().any(|&m| m == c) + self.contains(&c) } } impl MultiCharEq for &[char] { #[inline] fn matches(&mut self, c: char) -> bool { - self.iter().any(|&m| m == c) + self.contains(&c) } } |
