mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
Use get_unchecked in str::[r]split_once
This commit is contained in:
parent
197fc8591e
commit
a35aaa2108
@ -1524,7 +1524,8 @@ impl str {
|
||||
#[inline]
|
||||
pub fn split_once<'a, P: Pattern<'a>>(&'a self, delimiter: P) -> Option<(&'a str, &'a str)> {
|
||||
let (start, end) = delimiter.into_searcher(self).next_match()?;
|
||||
Some((&self[..start], &self[end..]))
|
||||
// SAFETY: `Searcher` is known to return valid indices.
|
||||
unsafe { Some((self.get_unchecked(..start), self.get_unchecked(end..))) }
|
||||
}
|
||||
|
||||
/// Splits the string on the last occurrence of the specified delimiter and
|
||||
@ -1544,7 +1545,8 @@ impl str {
|
||||
P: Pattern<'a, Searcher: ReverseSearcher<'a>>,
|
||||
{
|
||||
let (start, end) = delimiter.into_searcher(self).next_match_back()?;
|
||||
Some((&self[..start], &self[end..]))
|
||||
// SAFETY: `Searcher` is known to return valid indices.
|
||||
unsafe { Some((self.get_unchecked(..start), self.get_unchecked(end..))) }
|
||||
}
|
||||
|
||||
/// An iterator over the disjoint matches of a pattern within the given string
|
||||
|
Loading…
Reference in New Issue
Block a user