This enables constant folding when matching a literal char.
Fixes #41993.
#[inline]
fn is_prefix_of(self, haystack: &'a str) -> bool {
- if let Some(ch) = haystack.chars().next() {
- self == ch
- } else {
- false
- }
+ let mut buffer = [0u8; 4];
+ self.encode_utf8(&mut buffer).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
- }
+ let mut buffer = [0u8; 4];
+ self.encode_utf8(&mut buffer).is_suffix_of(haystack)
}
}