about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniPopes <57450786+DaniPopes@users.noreply.github.com>2025-04-26 22:06:42 +0200
committerDaniPopes <57450786+DaniPopes@users.noreply.github.com>2025-04-26 22:06:44 +0200
commit6f5698c3683f0b158399c0c22c88234dfb695c29 (patch)
tree41dd6b28c649bcabb61d9636e764ae241f8307ec
parent10fa3c449f6b1613b352a6cbf78d3d91fd9a1d81 (diff)
downloadrust-6f5698c3683f0b158399c0c22c88234dfb695c29.tar.gz
rust-6f5698c3683f0b158399c0c22c88234dfb695c29.zip
Avoid re-interning in `LateContext::get_def_path`
The def path printer in `get_def_path` essentially calls
`Symbol::intern(&symbol.to_string())` for simple symbols in a path.
This accounts for ~30% of the runtime of get_def_path.

We can avoid this by simply appending the symbol directly when available.
-rw-r--r--compiler/rustc_lint/src/context.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs
index 3660bb3f780..5679d4566dc 100644
--- a/compiler/rustc_lint/src/context.rs
+++ b/compiler/rustc_lint/src/context.rs
@@ -812,7 +812,10 @@ impl<'tcx> LateContext<'tcx> {
                     return Ok(());
                 }
 
-                self.path.push(Symbol::intern(&disambiguated_data.data.to_string()));
+                self.path.push(match disambiguated_data.data.get_opt_name() {
+                    Some(sym) => sym,
+                    None => Symbol::intern(&disambiguated_data.data.to_string()),
+                });
                 Ok(())
             }