diff options
| author | bors <bors@rust-lang.org> | 2014-09-09 23:55:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-09-09 23:55:43 +0000 |
| commit | a1f49730906ca27947cd99547f7295a1bcf83920 (patch) | |
| tree | 4894feeb3041bedbce1a7febdf2916e142dcbede /src/libcoretest | |
| parent | 651106462c357b71a4ca2c02ba2bfedfc38b0035 (diff) | |
| parent | fcf88b8f87597f97112f048eaa296b3127e51d0b (diff) | |
| download | rust-a1f49730906ca27947cd99547f7295a1bcf83920.tar.gz rust-a1f49730906ca27947cd99547f7295a1bcf83920.zip | |
auto merge of #16662 : pczarn/rust/format-fmtstr-opt, r=brson
Based on an observation that strings and arguments are always interleaved, thanks to #15832. Additionally optimize invocations where formatting parameters are unspecified for all arguments, e.g. `"{} {:?} {:x}"`, by emptying the `__STATIC_FMTARGS` array. Next, `Arguments::new` replaces an empty slice with `None` so that passing empty `__STATIC_FMTARGS` generates slightly less machine code when `Arguments::new` is inlined. Furthermore, formatting itself treats these cases separately without making redundant copies of formatting parameters.
All in all, this adds a single mov instruction per `write!` in most cases. That's why code size has increased.
Diffstat (limited to 'src/libcoretest')
| -rw-r--r-- | src/libcoretest/fmt/mod.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libcoretest/fmt/mod.rs b/src/libcoretest/fmt/mod.rs index 9fc09b3124e..3f2208e6c2d 100644 --- a/src/libcoretest/fmt/mod.rs +++ b/src/libcoretest/fmt/mod.rs @@ -9,3 +9,10 @@ // except according to those terms. mod num; + +#[test] +fn test_format_flags() { + // No residual flags left by pointer formatting + let p = "".as_ptr(); + assert_eq!(format!("{:p} {:x}", p, 16u), format!("{:p} 10", p)); +} |
