Skip to content

Commit 8b87fef

Browse files
committed
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)
2 parents d497e43 + bfe5363 commit 8b87fef

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎library/core/src/slice/cmp.rs‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,21 +644,21 @@ where
644644
impl<constN:usize>MultiCharEqfor[char;N]{
645645
#[inline]
646646
fnmatches(&mutself,c:char) -> bool{
647-
self.iter().any(|&m| m == c)
647+
self.contains(&c)
648648
}
649649
}
650650

651651
impl<constN:usize>MultiCharEqfor&[char;N]{
652652
#[inline]
653653
fnmatches(&mutself,c:char) -> bool{
654-
self.iter().any(|&m| m == c)
654+
self.contains(&c)
655655
}
656656
}
657657

658658
implMultiCharEqfor&[char]{
659659
#[inline]
660660
fnmatches(&mutself,c:char) -> bool{
661-
self.iter().any(|&m| m == c)
661+
self.contains(&c)
662662
}
663663
}
664664

0 commit comments

Comments
 (0)