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 @@ -1524,7 +1524,8 @@ impl str {
1524
1524
#[ inline]
1525
1525
pub fn split_once < ' a , P : Pattern < ' a > > ( & ' a self , delimiter : P ) -> Option < ( & ' a str , & ' a str ) > {
1526
1526
let ( start, end) = delimiter. into_searcher ( self ) . next_match ( ) ?;
1527
- Some ( ( & self [ ..start] , & self [ end..] ) )
1527
+ // SAFETY: `Searcher` is known to return valid indices.
1528
+ unsafe { Some ( ( self . get_unchecked ( ..start) , self . get_unchecked ( end..) ) ) }
1528
1529
}
1529
1530
1530
1531
/// Splits the string on the last occurrence of the specified delimiter and
@@ -1544,7 +1545,8 @@ impl str {
1544
1545
P : Pattern < ' a , Searcher : ReverseSearcher < ' a > > ,
1545
1546
{
1546
1547
let ( start, end) = delimiter. into_searcher ( self ) . next_match_back ( ) ?;
1547
- Some ( ( & self [ ..start] , & self [ end..] ) )
1548
+ // SAFETY: `Searcher` is known to return valid indices.
1549
+ unsafe { Some ( ( self . get_unchecked ( ..start) , self . get_unchecked ( end..) ) ) }
1548
1550
}
1549
1551
1550
1552
/// 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