Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use rustc_span::def_id::DefId;
use rustc_span::edition::Edition;
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
use rustc_target::spec::{PanicStrategy, Target};
use tracing::{debug, info, trace};
use tracing::{debug, info};

use crate::diagnostics;
use crate::locator::{CrateError, CrateLocator, CratePaths, CrateRejections};
Expand Down Expand Up @@ -69,6 +69,9 @@ pub struct CStore {
/// This crate has a `#[alloc_error_handler]` item.
has_alloc_error_handler: bool,

/// Cached map from hash to CrateNum, to avoid scanning metas during crate resolution.
hash_to_cnum: UnordMap<Svh, CrateNum>,

/// Names that were used to load the crates via `extern crate` or paths.
resolved_externs: UnordMap<Symbol, CrateNum>,

Expand Down Expand Up @@ -237,6 +240,7 @@ impl CStore {

fn set_crate_data(&mut self, cnum: CrateNum, data: CrateMetadata) {
assert!(self.metas[cnum].is_none(), "Overwriting crate metadata entry");
self.hash_to_cnum.insert(data.hash(), cnum);
self.metas[cnum] = Some(Box::new(data));
}

Expand Down Expand Up @@ -546,6 +550,7 @@ impl CStore {
alloc_error_handler_kind: None,
has_global_allocator: false,
has_alloc_error_handler: false,
hash_to_cnum: UnordMap::default(),
resolved_externs: UnordMap::default(),
unused_externs: Vec::new(),
used_extern_options: Default::default(),
Expand All @@ -555,21 +560,9 @@ impl CStore {

fn existing_match(&self, name: Symbol, hash: Option<Svh>) -> Option<CrateNum> {
let hash = hash?;

for (cnum, data) in self.iter_crate_data() {
if data.name() != name {
trace!("{} did not match {}", data.name(), name);
continue;
}

if hash == data.hash() {
return Some(cnum);
} else {
debug!("actual hash {} did not match expected {}", hash, data.hash());
}
}

None
let cnum = *self.hash_to_cnum.get(&hash)?;
debug_assert_eq!(self.get_crate_data(cnum).name(), name);
Some(cnum)
}

/// Determine whether a dependency should be considered private.
Expand Down
Loading