Skip to content

Commit 4d7ec70

Browse files
authored
Rollup merge of #70046 - lzutao:patch-1, r=Centril
Use sublice patterns to avoid computing the len r? @Centril
2 parents f907598 + e1bc9af commit 4d7ec70

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/libstd/sys_common/wtf8.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -599,24 +599,16 @@ impl Wtf8 {
599599

600600
#[inline]
601601
fn final_lead_surrogate(&self) -> Option<u16> {
602-
let len = self.len();
603-
if len < 3 {
604-
return None;
605-
}
606-
match self.bytes[(len - 3)..] {
607-
[0xED, b2 @ 0xA0..=0xAF, b3] => Some(decode_surrogate(b2, b3)),
602+
match self.bytes {
603+
[.., 0xED, b2 @ 0xA0..=0xAF, b3] => Some(decode_surrogate(b2, b3)),
608604
_ => None,
609605
}
610606
}
611607

612608
#[inline]
613609
fn initial_trail_surrogate(&self) -> Option<u16> {
614-
let len = self.len();
615-
if len < 3 {
616-
return None;
617-
}
618-
match self.bytes[..3] {
619-
[0xED, b2 @ 0xB0..=0xBF, b3] => Some(decode_surrogate(b2, b3)),
610+
match self.bytes {
611+
[0xED, b2 @ 0xB0..=0xBF, b3, ..] => Some(decode_surrogate(b2, b3)),
620612
_ => None,
621613
}
622614
}

0 commit comments

Comments
 (0)