From ca935ddbf104b8b48eea8106f19e6a87f628d897 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 30 Jun 2021 18:39:28 +0200 Subject: [PATCH] Make tcx.stable_crate_id() faster --- compiler/rustc_middle/src/ty/context.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index abf839711b332..9c98592c86518 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1299,8 +1299,12 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn stable_crate_id(self, cnum: CrateNum) -> StableCrateId { - self.def_path_hash(cnum.as_def_id()).stable_crate_id() + pub fn stable_crate_id(self, crate_num: CrateNum) -> StableCrateId { + if crate_num == LOCAL_CRATE { + self.sess.local_stable_crate_id() + } else { + self.cstore.stable_crate_id_untracked(crate_num) + } } pub fn def_path_debug_str(self, def_id: DefId) -> String {