Skip to content

Commit 33ef4b9

Browse files
committed
Optimize Symbol::integer by utilizing itoa in-place formatting
1 parent 1547c07 commit 33ef4b9

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4570,6 +4570,7 @@ name = "rustc_span"
45704570
version = "0.0.0"
45714571
dependencies = [
45724572
"indexmap",
4573+
"itoa",
45734574
"md-5",
45744575
"rustc_arena",
45754576
"rustc_data_structures",

compiler/rustc_span/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
indexmap = { version = "2.0.0" }
9+
itoa = "1.0"
910
md5 = { package = "md-5", version = "0.10.0" }
1011
rustc_arena = { path = "../rustc_arena" }
1112
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_span/src/symbol.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2325,13 +2325,15 @@ pub mod sym {
23252325
///
23262326
/// The first few non-negative integers each have a static symbol and therefore
23272327
/// are fast.
2328-
pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
2328+
pub fn integer<N: TryInto<usize> + Copy + itoa::Integer>(n: N) -> Symbol {
23292329
if let Result::Ok(idx) = n.try_into() {
23302330
if idx < 10 {
23312331
return Symbol::new(super::SYMBOL_DIGITS_BASE + idx as u32);
23322332
}
23332333
}
2334-
Symbol::intern(&n.to_string())
2334+
let mut buffer = itoa::Buffer::new();
2335+
let printed = buffer.format(n);
2336+
Symbol::intern(printed)
23352337
}
23362338
}
23372339

0 commit comments

Comments
 (0)