Auto merge of #75121 - tmiasko:str-slicing, r=Mark-Simulacrum
Avoid `unwrap_or_else` in str indexing This provides a small reduction of generated LLVM IR, and leads to a simpler assembly code. Closes #68874.
This commit is contained in:
commit
98922795f6
1 changed files with 12 additions and 3 deletions
|
@ -1923,7 +1923,10 @@ mod traits {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(self, slice: &str) -> &Self::Output {
|
fn index(self, slice: &str) -> &Self::Output {
|
||||||
let (start, end) = (self.start, self.end);
|
let (start, end) = (self.start, self.end);
|
||||||
self.get(slice).unwrap_or_else(|| super::slice_error_fail(slice, start, end))
|
match self.get(slice) {
|
||||||
|
Some(s) => s,
|
||||||
|
None => super::slice_error_fail(slice, start, end),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
|
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
|
||||||
|
@ -1995,7 +1998,10 @@ mod traits {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(self, slice: &str) -> &Self::Output {
|
fn index(self, slice: &str) -> &Self::Output {
|
||||||
let end = self.end;
|
let end = self.end;
|
||||||
self.get(slice).unwrap_or_else(|| super::slice_error_fail(slice, 0, end))
|
match self.get(slice) {
|
||||||
|
Some(s) => s,
|
||||||
|
None => super::slice_error_fail(slice, 0, end),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
|
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
|
||||||
|
@ -2068,7 +2074,10 @@ mod traits {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(self, slice: &str) -> &Self::Output {
|
fn index(self, slice: &str) -> &Self::Output {
|
||||||
let (start, end) = (self.start, slice.len());
|
let (start, end) = (self.start, slice.len());
|
||||||
self.get(slice).unwrap_or_else(|| super::slice_error_fail(slice, start, end))
|
match self.get(slice) {
|
||||||
|
Some(s) => s,
|
||||||
|
None => super::slice_error_fail(slice, start, end),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
|
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue