Skip to content

Commit bfe5363

Browse files
committed
Optimize multi-char string patterns
1 parent aa95b96 commit bfe5363

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

library/core/src/slice/cmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,4 @@ macro_rules! impl_slice_contains {
282282
};
283283
}
284284

285-
impl_slice_contains!(u16, u32, u64, i16, i32, i64, f32, f64, usize, isize);
285+
impl_slice_contains!(u16, u32, u64, i16, i32, i64, f32, f64, usize, isize, char);

library/core/src/str/pattern.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -644,21 +644,21 @@ where
644644
impl<const N: usize> MultiCharEq for [char; N] {
645645
#[inline]
646646
fn matches(&mut self, c: char) -> bool {
647-
self.iter().any(|&m| m == c)
647+
self.contains(&c)
648648
}
649649
}
650650

651651
impl<const N: usize> MultiCharEq for &[char; N] {
652652
#[inline]
653653
fn matches(&mut self, c: char) -> bool {
654-
self.iter().any(|&m| m == c)
654+
self.contains(&c)
655655
}
656656
}
657657

658658
impl MultiCharEq for &[char] {
659659
#[inline]
660660
fn matches(&mut self, c: char) -> bool {
661-
self.iter().any(|&m| m == c)
661+
self.contains(&c)
662662
}
663663
}
664664

0 commit comments

Comments
 (0)