about summary refs log tree commit diff
path: root/src/libstd/sys_common
diff options
context:
space:
mode:
authorlzutao <taolzu@gmail.com>2020-03-16 23:43:42 +0700
committerGitHub <noreply@github.com>2020-03-16 23:43:42 +0700
commitce5e49f86fc8bff241695f8a62e77f517749bd6d (patch)
tree5c247b5d7491b7a0b93038b4465962631809e4f7 /src/libstd/sys_common
parent59f4ba95045e91a63e921e0d736242d7e1ffabec (diff)
downloadrust-ce5e49f86fc8bff241695f8a62e77f517749bd6d.tar.gz
rust-ce5e49f86fc8bff241695f8a62e77f517749bd6d.zip
Use sublice patterns to avoid computing the len
Diffstat (limited to 'src/libstd/sys_common')
-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..77977e25517 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,
         }
     }