diff options
| author | Urgau <urgau@numericable.fr> | 2024-03-06 19:39:36 +0100 |
|---|---|---|
| committer | Urgau <urgau@numericable.fr> | 2024-03-06 19:39:36 +0100 |
| commit | 33ef4b963bb9f24119e638f91d08241ba71f0ca2 (patch) | |
| tree | 62e8528abc2ff9c556705c30e93ddb3f635ee662 | |
| parent | 1547c076bfec8abb819d6a81e1e4095d267bd5b4 (diff) | |
| download | rust-33ef4b963bb9f24119e638f91d08241ba71f0ca2.tar.gz rust-33ef4b963bb9f24119e638f91d08241ba71f0ca2.zip | |
Optimize Symbol::integer by utilizing itoa in-place formatting
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | compiler/rustc_span/Cargo.toml | 1 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 6 |
3 files changed, 6 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock index 5feb21a65b7..c12b23e87fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4570,6 +4570,7 @@ name = "rustc_span" version = "0.0.0" dependencies = [ "indexmap", + "itoa", "md-5", "rustc_arena", "rustc_data_structures", diff --git a/compiler/rustc_span/Cargo.toml b/compiler/rustc_span/Cargo.toml index 99de91a068a..98ed985738a 100644 --- a/compiler/rustc_span/Cargo.toml +++ b/compiler/rustc_span/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start indexmap = { version = "2.0.0" } +itoa = "1.0" md5 = { package = "md-5", version = "0.10.0" } rustc_arena = { path = "../rustc_arena" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 3784a08b1b7..96ad1e81e79 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2325,13 +2325,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) } } |
