File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -513,17 +513,16 @@ impl<'a, 'b> Pattern<'a> for &'b str {
513513 /// Checks whether the pattern matches at the front of the haystack
514514 #[ inline]
515515 fn is_prefix_of ( self , haystack : & ' a str ) -> bool {
516- // Use `as_bytes` so that we can slice through a character in the haystack.
517- // Since self is always valid UTF-8, this can't result in a false positive.
518- self . len ( ) <= haystack. len ( ) &&
519- self . as_bytes ( ) == & haystack. as_bytes ( ) [ ..self . len ( ) ]
516+ haystack. is_char_boundary ( self . len ( ) ) &&
517+ self == & haystack[ ..self . len ( ) ]
520518 }
521519
522520 /// Checks whether the pattern matches at the back of the haystack
523521 #[ inline]
524522 fn is_suffix_of ( self , haystack : & ' a str ) -> bool {
525523 self . len ( ) <= haystack. len ( ) &&
526- self . as_bytes ( ) == & haystack. as_bytes ( ) [ haystack. len ( ) - self . len ( ) ..]
524+ haystack. is_char_boundary ( haystack. len ( ) - self . len ( ) ) &&
525+ self == & haystack[ haystack. len ( ) - self . len ( ) ..]
527526 }
528527}
529528
You can’t perform that action at this time.
0 commit comments