]> git.lizzy.rs Git - rust.git/commitdiff
Misc cleanups
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Sun, 6 Jan 2019 06:36:14 +0000 (15:36 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Tue, 8 Jan 2019 21:31:09 +0000 (06:31 +0900)
src/libcore/fmt/mod.rs
src/libcore/str/pattern.rs

index 0127277d9cfc8d08392b5f1da5920fba897a0ca0..214b5d3a84f24c4bb3f88af4cb8063eea18545a0 100644 (file)
@@ -1076,7 +1076,7 @@ fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<usize> {
                 self.args[i].as_usize()
             }
             rt::v1::Count::NextParam => {
-                self.curarg.next().and_then(|arg| arg.as_usize())
+                self.curarg.next()?.as_usize()
             }
         }
     }
@@ -1142,15 +1142,15 @@ pub fn pad_integral(&mut self,
             sign = Some('+'); width += 1;
         }
 
-        let mut prefixed = false;
-        if self.alternate() {
-            prefixed = true; width += prefix.chars().count();
+        let prefixed = self.alternate();
+        if prefixed {
+            width += prefix.chars().count();
         }
 
         // Writes the sign if it exists, and then the prefix if it was requested
         let write_prefix = |f: &mut Formatter| {
             if let Some(c) = sign {
-                f.buf.write_str(c.encode_utf8(&mut [0; 4]))?;
+                f.buf.write_char(c)?;
             }
             if prefixed { f.buf.write_str(prefix) }
             else { Ok(()) }
@@ -1312,7 +1312,7 @@ fn pad_formatted_parts(&mut self, formatted: &flt2dec::Formatted) -> Result {
 
                 // remove the sign from the formatted parts
                 formatted.sign = b"";
-                width = if width < sign.len() { 0 } else { width - sign.len() };
+                width = width.saturating_sub(sign.len());
                 align = rt::v1::Alignment::Right;
                 self.fill = '0';
                 self.align = rt::v1::Alignment::Right;
index b4eae4d1bb742bc9a2df473f652810176b8c8f31..55a7ba181e5271d5a4e7f8188ba3714934e765d1 100644 (file)
@@ -425,8 +425,7 @@ impl<'a> Pattern<'a> for char {
     #[inline]
     fn into_searcher(self, haystack: &'a str) -> Self::Searcher {
         let mut utf8_encoded = [0; 4];
-        self.encode_utf8(&mut utf8_encoded);
-        let utf8_size = self.len_utf8();
+        let utf8_size = self.encode_utf8(&mut utf8_encoded).len();
         CharSearcher {
             haystack,
             finger: 0,