Skip to content

Commit fd20a8b

Browse files
committed
Auto merge of rust-lang#81453 - jumbatm:clashing-extern-decl-perf, r=nagisa
clashing_extern_declarations: Use symbol interning to avoid string alloc. Use symbol interning as a hack to avoid allocating a string for every symbol name we store in the seen set. This hopefully addresses the minor perf regression described in rust-lang#80009 (comment). r? `@nagisa`
2 parents 7ce1b3b + a1a7830 commit fd20a8b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compiler/rustc_lint/src/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2607,7 +2607,7 @@ pub struct ClashingExternDeclarations {
26072607
/// the symbol should be reported as a clashing declaration.
26082608
// FIXME: Technically, we could just store a &'tcx str here without issue; however, the
26092609
// `impl_lint_pass` macro doesn't currently support lints parametric over a lifetime.
2610-
seen_decls: FxHashMap<String, HirId>,
2610+
seen_decls: FxHashMap<Symbol, HirId>,
26112611
}
26122612

26132613
/// Differentiate between whether the name for an extern decl came from the link_name attribute or
@@ -2641,14 +2641,14 @@ impl ClashingExternDeclarations {
26412641
let local_did = tcx.hir().local_def_id(fi.hir_id);
26422642
let did = local_did.to_def_id();
26432643
let instance = Instance::new(did, ty::List::identity_for_item(tcx, did));
2644-
let name = tcx.symbol_name(instance).name;
2645-
if let Some(&hir_id) = self.seen_decls.get(name) {
2644+
let name = Symbol::intern(tcx.symbol_name(instance).name);
2645+
if let Some(&hir_id) = self.seen_decls.get(&name) {
26462646
// Avoid updating the map with the new entry when we do find a collision. We want to
26472647
// make sure we're always pointing to the first definition as the previous declaration.
26482648
// This lets us avoid emitting "knock-on" diagnostics.
26492649
Some(hir_id)
26502650
} else {
2651-
self.seen_decls.insert(name.to_owned(), hid)
2651+
self.seen_decls.insert(name, hid)
26522652
}
26532653
}
26542654

0 commit comments

Comments
 (0)