From cb3df68743c725da1ea2c8781359518e140d07f9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 21 Apr 2026 22:05:19 +1000 Subject: [PATCH] Streamline `CrateMetadataRef` construction in `provide_one!`. `cstore.get_crate_data()` creates a `CrateMetadataRef`, which is exactly what we need. The current code is very confused and does several unnecessary things: mapping the `FreezeReadGuard` and calling `CStore::from_tcx` a second time to construct a second `CrateMetadataRef`. This is a small perf win. --- compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index f9f746188f23..ea1e4d94214a 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -152,13 +152,8 @@ fn $name<'tcx>( $tcx.ensure_ok().crate_hash($def_id.krate); } - let cdata = rustc_data_structures::sync::FreezeReadGuard::map(CStore::from_tcx($tcx), |c| { - c.get_crate_data($def_id.krate).cdata - }); - let $cdata = crate::creader::CrateMetadataRef { - cdata: &cdata, - cstore: &CStore::from_tcx($tcx), - }; + let cstore = CStore::from_tcx($tcx); + let $cdata = cstore.get_crate_data($def_id.krate); $compute }