about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-17 03:05:19 +0100
committerGitHub <noreply@github.com>2020-03-17 03:05:19 +0100
commit4d7ec704ccb7873059522d02b82204d9f775ce32 (patch)
tree47ad9d76ee24e6dc2b7cd48f513a649ee275686f
parentf907598ba475a5003b9584ef19cf2b761ff53de2 (diff)
parente1bc9af9eb503e7ca0027b4d7086c35cd661140e (diff)
downloadrust-4d7ec704ccb7873059522d02b82204d9f775ce32.tar.gz
rust-4d7ec704ccb7873059522d02b82204d9f775ce32.zip
Rollup merge of #70046 - lzutao:patch-1, r=Centril
Use sublice patterns to avoid computing the len

r? @Centril
-rw-r--r--src/libstd/sys_common/wtf8.rs16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs
index 7509e1ee35d..498950e6821 100644
--- a/src/libstd/sys_common/wtf8.rs
+++ b/src/libstd/sys_common/wtf8.rs
@@ -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,
         }
     }