Skip to content

Commit

Permalink
Rollup merge of rust-lang#70046 - lzutao:patch-1, r=Centril
Browse files Browse the repository at this point in the history
Use sublice patterns to avoid computing the len

r? @Centril
  • Loading branch information
Centril authored Mar 16, 2020
2 parents 140529e + e1bc9af commit a56761d
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/libstd/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,24 +599,16 @@ impl Wtf8 {

#[inline]
fn final_lead_surrogate(&self) -> Option<u16> {
let len = self.len();
if len < 3 {
return None;
}
match self.bytes[(len - 3)..] {
[0xED, b2 @ 0xA0..=0xAF, b3] => Some(decode_surrogate(b2, b3)),
match self.bytes {
[.., 0xED, b2 @ 0xA0..=0xAF, b3] => Some(decode_surrogate(b2, b3)),
_ => None,
}
}

#[inline]
fn initial_trail_surrogate(&self) -> Option<u16> {
let len = self.len();
if len < 3 {
return None;
}
match self.bytes[..3] {
[0xED, b2 @ 0xB0..=0xBF, b3] => Some(decode_surrogate(b2, b3)),
match self.bytes {
[0xED, b2 @ 0xB0..=0xBF, b3, ..] => Some(decode_surrogate(b2, b3)),
_ => None,
}
}
Expand Down

0 comments on commit a56761d

Please sign in to comment.