diff options
| author | bors <bors@rust-lang.org> | 2024-03-09 08:47:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-09 08:47:57 +0000 |
| commit | 9d272a1b0501f96da0ed10caa1b2eb6dbb653686 (patch) | |
| tree | 0218c61c838a1c2dac97f5bb1bdb01028d100a8c /compiler/rustc_span/src | |
| parent | 48a15aa2c496db70e14db62d6a477b23fc316e3c (diff) | |
| parent | 33ef4b963bb9f24119e638f91d08241ba71f0ca2 (diff) | |
| download | rust-9d272a1b0501f96da0ed10caa1b2eb6dbb653686.tar.gz rust-9d272a1b0501f96da0ed10caa1b2eb6dbb653686.zip | |
Auto merge of #122102 - Urgau:optimize-symbol-integer, r=cjgillot
Optimize `Symbol::integer` by utilizing in-place formatting This PR optimize `Symbol::integer` by utilizing `itoa` in-place formatting instead of going through a dynamically allocated `String` and the format machinery. <details> For some context: I was profiling `rustc --check-cfg` with callgrind and due to the way we currently setup all the targets and we end-up calling `Symbol::integer` multiple times for all the targets. Using `itoa` reduced the number of instructions. </details>
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9dadd471247..80c4dcb6b18 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2327,13 +2327,15 @@ pub mod sym { /// /// The first few non-negative integers each have a static symbol and therefore /// are fast. - pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol { + pub fn integer<N: TryInto<usize> + Copy + itoa::Integer>(n: N) -> Symbol { if let Result::Ok(idx) = n.try_into() { if idx < 10 { return Symbol::new(super::SYMBOL_DIGITS_BASE + idx as u32); } } - Symbol::intern(&n.to_string()) + let mut buffer = itoa::Buffer::new(); + let printed = buffer.format(n); + Symbol::intern(printed) } } |
