Skip to content

Commit d7a7ce9

Browse files
committed
Utilize specialized zip iterator impl
name old ns/iter new ns/iter diff ns/iter diff % speedup fmt::write_str_macro1 13,927 12,489 -1,438 -10.33% x 1.12 fmt::write_str_macro2 24,633 23,418 -1,215 -4.93% x 1.05 fmt::write_str_macro_debug 234,633 233,092 -1,541 -0.66% x 1.01 fmt::write_str_ref 5,819 5,823 4 0.07% x 1.00 fmt::write_str_value 6,012 5,828 -184 -3.06% x 1.03 fmt::write_vec_macro1 18,550 17,143 -1,407 -7.58% x 1.08 fmt::write_vec_macro2 30,369 28,920 -1,449 -4.77% x 1.05 fmt::write_vec_macro_debug 244,338 244,901 563 0.23% x 1.00 fmt::write_vec_ref 5,952 5,885 -67 -1.13% x 1.01 fmt::write_vec_value 5,944 5,894 -50 -0.84% x 1.01
1 parent 0f34e0d commit d7a7ce9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/libcore/fmt/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,28 +1026,30 @@ pub fn write(output: &mut dyn Write, args: Arguments) -> Result {
10261026
curarg: args.args.iter(),
10271027
};
10281028

1029-
let mut pieces = args.pieces.iter();
1029+
let mut idx = 0;
10301030

10311031
match args.fmt {
10321032
None => {
10331033
// We can use default formatting parameters for all arguments.
1034-
for (arg, piece) in args.args.iter().zip(pieces.by_ref()) {
1034+
for (arg, piece) in args.args.iter().zip(args.pieces.iter()) {
10351035
formatter.buf.write_str(*piece)?;
10361036
(arg.formatter)(arg.value, &mut formatter)?;
1037+
idx += 1;
10371038
}
10381039
}
10391040
Some(fmt) => {
10401041
// Every spec has a corresponding argument that is preceded by
10411042
// a string piece.
1042-
for (arg, piece) in fmt.iter().zip(pieces.by_ref()) {
1043+
for (arg, piece) in fmt.iter().zip(args.pieces.iter()) {
10431044
formatter.buf.write_str(*piece)?;
10441045
formatter.run(arg)?;
1046+
idx += 1;
10451047
}
10461048
}
10471049
}
10481050

10491051
// There can be only one trailing string piece left.
1050-
if let Some(piece) = pieces.next() {
1052+
if let Some(piece) = args.pieces.get(idx) {
10511053
formatter.buf.write_str(*piece)?;
10521054
}
10531055

0 commit comments

Comments
 (0)