]> git.lizzy.rs Git - rust.git/commitdiff
Some small readability improvements
authorAndre Bogus <bogusandre@gmail.com>
Wed, 11 Dec 2019 19:49:46 +0000 (20:49 +0100)
committerAndre Bogus <bogusandre@gmail.com>
Wed, 11 Dec 2019 19:49:46 +0000 (20:49 +0100)
src/libcore/char/methods.rs
src/libcore/str/pattern.rs

index 1ec614edbe2ebdd1d67728e2e613fcda3f946489..5c63eebf595f9e59d32690b46488513db72ddade 100644 (file)
@@ -553,8 +553,7 @@ pub fn encode_utf16(self, dst: &mut [u16]) -> &mut [u16] {
     pub fn is_alphabetic(self) -> bool {
         match self {
             'a'..='z' | 'A'..='Z' => true,
-            c if c > '\x7f' => derived_property::Alphabetic(c),
-            _ => false,
+            c => c > '\x7f' && derived_property::Alphabetic(c),
         }
     }
 
@@ -585,8 +584,7 @@ pub fn is_alphabetic(self) -> bool {
     pub fn is_lowercase(self) -> bool {
         match self {
             'a'..='z' => true,
-            c if c > '\x7f' => derived_property::Lowercase(c),
-            _ => false,
+            c => c > '\x7f' && derived_property::Lowercase(c),
         }
     }
 
@@ -617,8 +615,7 @@ pub fn is_lowercase(self) -> bool {
     pub fn is_uppercase(self) -> bool {
         match self {
             'A'..='Z' => true,
-            c if c > '\x7f' => derived_property::Uppercase(c),
-            _ => false,
+            c => c > '\x7f' && derived_property::Uppercase(c),
         }
     }
 
@@ -646,8 +643,7 @@ pub fn is_uppercase(self) -> bool {
     pub fn is_whitespace(self) -> bool {
         match self {
             ' ' | '\x09'..='\x0d' => true,
-            c if c > '\x7f' => property::White_Space(c),
-            _ => false,
+            c => c > '\x7f' && property::White_Space(c),
         }
     }
 
@@ -744,8 +740,7 @@ pub(crate) fn is_grapheme_extended(self) -> bool {
     pub fn is_numeric(self) -> bool {
         match self {
             '0'..='9' => true,
-            c if c > '\x7f' => general_category::N(c),
-            _ => false,
+            c => c > '\x7f' && general_category::N(c),
         }
     }
 
index a494274118a74171dfbf50da47664bcb2ff3628e..1037da14b5f627371d6678d799639d023590dee2 100644 (file)
@@ -296,12 +296,7 @@ fn next(&mut self) -> SearchStep {
     fn next_match(&mut self) -> Option<(usize, usize)> {
         loop {
             // get the haystack after the last character found
-            let bytes = if let Some(slice) = self.haystack.as_bytes()
-                                                 .get(self.finger..self.finger_back) {
-                slice
-            } else {
-                return None;
-            };
+            let bytes = self.haystack.as_bytes().get(self.finger..self.finger_back)?;
             // the last byte of the utf8 encoded needle
             let last_byte = unsafe { *self.utf8_encoded.get_unchecked(self.utf8_size - 1) };
             if let Some(index) = memchr::memchr(last_byte, bytes) {