Skip to content

Commit 0f01c3b

Browse files
author
Stjepan Glavina
committed
[Experiment] Replace HashMap with OrderMap
1 parent 2d75213 commit 0f01c3b

File tree

46 files changed

+2079
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2079
-29
lines changed

src/librustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rustc_errors = { path = "../librustc_errors" }
2323
serialize = { path = "../libserialize" }
2424
syntax = { path = "../libsyntax" }
2525
syntax_pos = { path = "../libsyntax_pos" }
26+
ordermap = { path = "../ordermap" }
2627

2728
# Note that these dependencies are a lie, they're just here to get linkage to
2829
# work.

src/librustc/dep_graph/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl DepGraphQuery {
4141
}
4242

4343
pub fn contains_node(&self, node: &DepNode) -> bool {
44-
self.indices.contains_key(&node)
44+
self.indices.contains_key(node)
4545
}
4646

4747
pub fn nodes(&self) -> Vec<&DepNode> {
@@ -83,7 +83,7 @@ impl DepGraphQuery {
8383

8484
/// Just the outgoing edges from `node`.
8585
pub fn immediate_successors(&self, node: &DepNode) -> Vec<&DepNode> {
86-
if let Some(&index) = self.indices.get(&node) {
86+
if let Some(&index) = self.indices.get(node) {
8787
self.graph.successor_nodes(index)
8888
.map(|s| self.graph.node_data(s))
8989
.collect()

src/librustc/ich/hcx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use session::Session;
2121
use std::cmp::Ord;
2222
use std::hash as std_hash;
2323
use std::cell::RefCell;
24-
use std::collections::HashMap;
24+
use ordermap::OrderMap;
2525

2626
use syntax::ast;
2727
use syntax::attr;
@@ -426,7 +426,7 @@ pub fn hash_stable_trait_impls<'gcx, W, R>(
426426
hcx: &mut StableHashingContext<'gcx>,
427427
hasher: &mut StableHasher<W>,
428428
blanket_impls: &Vec<DefId>,
429-
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
429+
non_blanket_impls: &OrderMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
430430
where W: StableHasherResult,
431431
R: std_hash::BuildHasher,
432432
{

src/librustc/infer/freshen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use ty::subst::Substs;
4747
use util::nodemap::FxHashMap;
4848
use hir::def_id::DefId;
4949

50-
use std::collections::hash_map::Entry;
50+
use ordermap::Entry;
5151

5252
use super::InferCtxt;
5353
use super::unify_key::ToType;

src/librustc/infer/region_inference/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use infer::region_inference::RegionVarBindings;
2828
use util::nodemap::{FxHashMap, FxHashSet};
2929

3030
use std::borrow::Cow;
31-
use std::collections::hash_map::Entry::Vacant;
31+
use ordermap::Entry::Vacant;
3232
use std::env;
3333
use std::fs::File;
3434
use std::io;

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
#![recursion_limit="256"]
6464

65+
extern crate ordermap;
6566
extern crate arena;
6667
#[macro_use] extern crate bitflags;
6768
extern crate core;

src/librustc/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
12631263
let trait_ref = &cache_fresh_trait_pred.0.trait_ref;
12641264
if self.can_use_global_caches(param_env) {
12651265
let cache = tcx.selection_cache.hashmap.borrow();
1266-
if let Some(cached) = cache.get(&trait_ref) {
1266+
if let Some(cached) = cache.get(trait_ref) {
12671267
return Some(cached.get(tcx));
12681268
}
12691269
}

src/librustc/ty/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
5353
use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
5454
StableHasher, StableHasherResult,
5555
StableVec};
56+
use rustc_data_structures;
5657
use arena::{TypedArena, DroplessArena};
5758
use rustc_const_math::{ConstInt, ConstUsize};
5859
use rustc_data_structures::indexed_vec::IndexVec;
5960
use std::any::Any;
6061
use std::borrow::Borrow;
6162
use std::cell::{Cell, RefCell};
6263
use std::cmp::Ordering;
63-
use std::collections::hash_map::{self, Entry};
64+
use ordermap::{self, Entry};
6465
use std::hash::{Hash, Hasher};
6566
use std::mem;
6667
use std::ops::Deref;
@@ -275,7 +276,7 @@ impl<'a, V> LocalTableInContext<'a, V> {
275276
self.data.get(&id.local_id)
276277
}
277278

278-
pub fn iter(&self) -> hash_map::Iter<hir::ItemLocalId, V> {
279+
pub fn iter(&self) -> ordermap::Iter<hir::ItemLocalId, V> {
279280
self.data.iter()
280281
}
281282
}
@@ -299,7 +300,7 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
299300
self.data.get_mut(&id.local_id)
300301
}
301302

302-
pub fn entry(&mut self, id: hir::HirId) -> Entry<hir::ItemLocalId, V> {
303+
pub fn entry(&mut self, id: hir::HirId) -> Entry<hir::ItemLocalId, V, ::std::hash::BuildHasherDefault<rustc_data_structures::fx::FxHasher>> {
303304
validate_hir_id_for_typeck_tables(self.local_id_root, id, true);
304305
self.data.entry(id.local_id)
305306
}

src/librustc_data_structures/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ crate-type = ["dylib"]
1111
[dependencies]
1212
log = "0.3"
1313
serialize = { path = "../libserialize" }
14+
ordermap = { path = "../ordermap" }

src/librustc_data_structures/fx.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::collections::{HashMap, HashSet};
11+
use std::collections::HashSet;
1212
use std::default::Default;
1313
use std::hash::{Hasher, Hash, BuildHasherDefault};
1414
use std::ops::BitXor;
15+
use ordermap::OrderMap;
1516

16-
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
17+
// pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
1718
pub type FxHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;
1819

20+
pub type FxHashMap<K, V> = OrderMap<K, V, BuildHasherDefault<FxHasher>>;
21+
1922
#[allow(non_snake_case)]
2023
pub fn FxHashMap<K: Hash + Eq, V>() -> FxHashMap<K, V> {
21-
HashMap::default()
24+
Default::default()
2225
}
2326

2427
#[allow(non_snake_case)]

0 commit comments

Comments
 (0)