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)
This commit is contained in:
commit
8b87fefd76
2 changed files with 4 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue