]> git.lizzy.rs Git - rust.git/commitdiff
Fix simple formatting optimization
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Sat, 12 Jan 2019 04:30:03 +0000 (13:30 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Sat, 12 Jan 2019 10:15:41 +0000 (19:15 +0900)
name                        old2 ns/iter  new2 ns/iter  diff ns/iter   diff %  speedup
fmt::write_str_macro1       12,295        12,308                  13    0.11%   x 1.00
fmt::write_str_macro2       24,079        21,451              -2,628  -10.91%   x 1.12
fmt::write_str_macro_debug  238,363       230,807             -7,556   -3.17%   x 1.03
fmt::write_str_ref          6,203         6,064                 -139   -2.24%   x 1.02
fmt::write_str_value        6,225         6,075                 -150   -2.41%   x 1.02
fmt::write_vec_macro1       17,144        17,121                 -23   -0.13%   x 1.00
fmt::write_vec_macro2       29,845        26,703              -3,142  -10.53%   x 1.12
fmt::write_vec_macro_debug  248,840       242,117             -6,723   -2.70%   x 1.03
fmt::write_vec_ref          5,954         6,438                  484    8.13%   x 0.92
fmt::write_vec_value        5,959         6,439                  480    8.06%   x 0.93

src/libfmt_macros/lib.rs
src/libsyntax_ext/format.rs

index 32ae878909f30676a76a4738b20400611f19148d..da440cdd72f8065d7266a09d8feaff3959dfdb15 100644 (file)
@@ -72,6 +72,15 @@ pub enum Position<'a> {
     ArgumentNamed(&'a str),
 }
 
+impl Position<'_> {
+    pub fn index(&self) -> Option<usize> {
+        match self {
+            ArgumentIs(i) | ArgumentImplicitlyIs(i) => Some(*i),
+            _ => None,
+        }
+    }
+}
+
 /// Enum of alignments which are supported.
 #[derive(Copy, Clone, PartialEq)]
 pub enum Alignment {
index 61722ba5516535a9ec5e3f3eea5bd2b3b4d8f7ef..0613c78e495903d33edfe3995b40d7e99c9a2ce3 100644 (file)
@@ -493,7 +493,10 @@ fn build_piece(&mut self,
 
                 let fill = arg.format.fill.unwrap_or(' ');
 
-                if *arg != simple_arg || fill != ' ' {
+                let pos_simple =
+                    arg.position.index() == simple_arg.position.index();
+
+                if !pos_simple || arg.format != simple_arg.format || fill != ' ' {
                     self.all_pieces_simple = false;
                 }