File tree 1 file changed +4
-2
lines changed
1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -1536,7 +1536,8 @@ impl str {
1536
1536
#[ inline]
1537
1537
pub fn split_once < ' a , P : Pattern < ' a > > ( & ' a self , delimiter : P ) -> Option < ( & ' a str , & ' a str ) > {
1538
1538
let ( start, end) = delimiter. into_searcher ( self ) . next_match ( ) ?;
1539
- Some ( ( & self [ ..start] , & self [ end..] ) )
1539
+ // SAFETY: `Searcher` is known to return valid indices.
1540
+ unsafe { Some ( ( self . get_unchecked ( ..start) , self . get_unchecked ( end..) ) ) }
1540
1541
}
1541
1542
1542
1543
/// Splits the string on the last occurrence of the specified delimiter and
@@ -1556,7 +1557,8 @@ impl str {
1556
1557
P : Pattern < ' a , Searcher : ReverseSearcher < ' a > > ,
1557
1558
{
1558
1559
let ( start, end) = delimiter. into_searcher ( self ) . next_match_back ( ) ?;
1559
- Some ( ( & self [ ..start] , & self [ end..] ) )
1560
+ // SAFETY: `Searcher` is known to return valid indices.
1561
+ unsafe { Some ( ( self . get_unchecked ( ..start) , self . get_unchecked ( end..) ) ) }
1560
1562
}
1561
1563
1562
1564
/// An iterator over the disjoint matches of a pattern within the given string
You can’t perform that action at this time.
0 commit comments