]> git.lizzy.rs Git - rust.git/commitdiff
Use symbol interning to avoid string alloc.
authorjumbatm <30644300+jumbatm@users.noreply.github.com>
Wed, 27 Jan 2021 22:03:36 +0000 (08:03 +1000)
committerjumbatm <30644300+jumbatm@users.noreply.github.com>
Wed, 27 Jan 2021 22:03:36 +0000 (08:03 +1000)
compiler/rustc_lint/src/builtin.rs

index b37660e4a90d3bb46b8b2656ae078dd55f327f62..d0e44550ee6e7a1675dd8192b417484ed03d131f 100644 (file)
@@ -2607,7 +2607,7 @@ pub struct ClashingExternDeclarations {
     /// the symbol should be reported as a clashing declaration.
     // FIXME: Technically, we could just store a &'tcx str here without issue; however, the
     // `impl_lint_pass` macro doesn't currently support lints parametric over a lifetime.
-    seen_decls: FxHashMap<String, HirId>,
+    seen_decls: FxHashMap<Symbol, HirId>,
 }
 
 /// Differentiate between whether the name for an extern decl came from the link_name attribute or
@@ -2641,14 +2641,14 @@ fn insert(&mut self, tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> Option<HirId
         let local_did = tcx.hir().local_def_id(fi.hir_id);
         let did = local_did.to_def_id();
         let instance = Instance::new(did, ty::List::identity_for_item(tcx, did));
-        let name = tcx.symbol_name(instance).name;
-        if let Some(&hir_id) = self.seen_decls.get(name) {
+        let name = Symbol::intern(tcx.symbol_name(instance).name);
+        if let Some(&hir_id) = self.seen_decls.get(&name) {
             // Avoid updating the map with the new entry when we do find a collision. We want to
             // make sure we're always pointing to the first definition as the previous declaration.
             // This lets us avoid emitting "knock-on" diagnostics.
             Some(hir_id)
         } else {
-            self.seen_decls.insert(name.to_owned(), hid)
+            self.seen_decls.insert(name, hid)
         }
     }