Skip to content

Commit 038d837

Browse files
committed
Fix simple formatting optimization
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
1 parent d7a7ce9 commit 038d837

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/libfmt_macros/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ pub enum Position<'a> {
7272
ArgumentNamed(&'a str),
7373
}
7474

75+
impl Position<'_> {
76+
pub fn index(&self) -> Option<usize> {
77+
match self {
78+
ArgumentIs(i) | ArgumentImplicitlyIs(i) => Some(*i),
79+
_ => None,
80+
}
81+
}
82+
}
83+
7584
/// Enum of alignments which are supported.
7685
#[derive(Copy, Clone, PartialEq)]
7786
pub enum Alignment {

src/libsyntax_ext/format.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ impl<'a, 'b> Context<'a, 'b> {
493493

494494
let fill = arg.format.fill.unwrap_or(' ');
495495

496-
if *arg != simple_arg || fill != ' ' {
496+
let pos_simple =
497+
arg.position.index() == simple_arg.position.index();
498+
499+
if !pos_simple || arg.format != simple_arg.format || fill != ' ' {
497500
self.all_pieces_simple = false;
498501
}
499502

0 commit comments

Comments
 (0)