Skip to content

Commit

Permalink
CStore switch FxHashMap to IndexVec
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Dec 27, 2017
1 parent 71ed31f commit 2c69473
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct CrateMetadata {
}

pub struct CStore {
metas: RefCell<FxHashMap<CrateNum, Rc<CrateMetadata>>>,
metas: RefCell<IndexVec<CrateNum, Option<Rc<CrateMetadata>>>>,
/// Map from NodeId's of local extern crate statements to crate numbers
extern_mod_crate_map: RefCell<NodeMap<CrateNum>>,
pub metadata_loader: Box<MetadataLoader>,
Expand All @@ -100,7 +100,7 @@ pub struct CStore {
impl CStore {
pub fn new(metadata_loader: Box<MetadataLoader>) -> CStore {
CStore {
metas: RefCell::new(FxHashMap()),
metas: RefCell::new(IndexVec::new()),
extern_mod_crate_map: RefCell::new(FxHashMap()),
metadata_loader,
}
Expand All @@ -111,18 +111,25 @@ impl CStore {
}

pub fn get_crate_data(&self, cnum: CrateNum) -> Rc<CrateMetadata> {
self.metas.borrow().get(&cnum).unwrap().clone()
self.metas.borrow()[cnum].clone().unwrap()
}

pub fn set_crate_data(&self, cnum: CrateNum, data: Rc<CrateMetadata>) {
self.metas.borrow_mut().insert(cnum, data);
use rustc_data_structures::indexed_vec::Idx;
let mut met = self.metas.borrow_mut();
while met.len() <= cnum.index() {
met.push(None);
}
met[cnum] = Some(data);
}

pub fn iter_crate_data<I>(&self, mut i: I)
where I: FnMut(CrateNum, &Rc<CrateMetadata>)
{
for (&k, v) in self.metas.borrow().iter() {
i(k, v);
for (k, v) in self.metas.borrow().iter_enumerated() {
if let &Some(ref v) = v {
i(k, v);
}
}
}

Expand Down Expand Up @@ -150,8 +157,10 @@ impl CStore {

pub fn do_postorder_cnums_untracked(&self) -> Vec<CrateNum> {
let mut ordering = Vec::new();
for (&num, _) in self.metas.borrow().iter() {
self.push_dependencies_in_postorder(&mut ordering, num);
for (num, v) in self.metas.borrow().iter_enumerated() {
if let &Some(_) = v {
self.push_dependencies_in_postorder(&mut ordering, num);
}
}
return ordering
}
Expand Down

0 comments on commit 2c69473

Please sign in to comment.