Skip to content

Commit 8f87538

Browse files
committed
auto merge of #18821 : arielb1/rust/fnv-hash-map, r=eddyb
This should improve performance
2 parents 5d29209 + 85f1262 commit 8f87538

35 files changed

+250
-289
lines changed

src/librustc/lint/builtin.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ use middle::typeck::infer;
3232
use middle::{typeck, ty, def, pat_util, stability};
3333
use middle::const_eval::{eval_const_expr_partial, const_int, const_uint};
3434
use util::ppaux::{ty_to_string};
35-
use util::nodemap::NodeSet;
35+
use util::nodemap::{FnvHashMap, NodeSet};
3636
use lint::{Context, LintPass, LintArray};
3737

3838
use std::cmp;
39-
use std::collections::HashMap;
4039
use std::collections::hash_map::{Occupied, Vacant};
4140
use std::slice;
4241
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
@@ -1284,7 +1283,7 @@ impl UnusedMut {
12841283
// collect all mutable pattern and group their NodeIDs by their Identifier to
12851284
// avoid false warnings in match arms with multiple patterns
12861285

1287-
let mut mutables = HashMap::new();
1286+
let mut mutables = FnvHashMap::new();
12881287
for p in pats.iter() {
12891288
pat_util::pat_bindings(&cx.tcx.def_map, &**p, |mode, id, _, path1| {
12901289
let ident = path1.node;

src/librustc/lint/context.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use driver::early_error;
3434
use lint::{Level, LevelSource, Lint, LintId, LintArray, LintPass, LintPassObject};
3535
use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid};
3636
use lint::builtin;
37+
use util::nodemap::FnvHashMap;
3738

38-
use std::collections::HashMap;
3939
use std::rc::Rc;
4040
use std::cell::RefCell;
4141
use std::tuple::Tuple2;
@@ -63,14 +63,14 @@ pub struct LintStore {
6363
passes: Option<Vec<LintPassObject>>,
6464

6565
/// Lints indexed by name.
66-
by_name: HashMap<String, TargetLint>,
66+
by_name: FnvHashMap<String, TargetLint>,
6767

6868
/// Current levels of each lint, and where they were set.
69-
levels: HashMap<LintId, LevelSource>,
69+
levels: FnvHashMap<LintId, LevelSource>,
7070

7171
/// Map of registered lint groups to what lints they expand to. The bool
7272
/// is true if the lint group was added by a plugin.
73-
lint_groups: HashMap<&'static str, (Vec<LintId>, bool)>,
73+
lint_groups: FnvHashMap<&'static str, (Vec<LintId>, bool)>,
7474
}
7575

7676
/// The targed of the `by_name` map, which accounts for renaming/deprecation.
@@ -102,9 +102,9 @@ impl LintStore {
102102
LintStore {
103103
lints: vec!(),
104104
passes: Some(vec!()),
105-
by_name: HashMap::new(),
106-
levels: HashMap::new(),
107-
lint_groups: HashMap::new(),
105+
by_name: FnvHashMap::new(),
106+
levels: FnvHashMap::new(),
107+
lint_groups: FnvHashMap::new(),
108108
}
109109
}
110110

@@ -279,7 +279,8 @@ impl LintStore {
279279
Some(lint_id) => self.set_level(lint_id, (level, CommandLine)),
280280
None => {
281281
match self.lint_groups.iter().map(|(&x, pair)| (x, pair.ref0().clone()))
282-
.collect::<HashMap<&'static str, Vec<LintId>>>()
282+
.collect::<FnvHashMap<&'static str,
283+
Vec<LintId>>>()
283284
.find_equiv(lint_name.as_slice()) {
284285
Some(v) => {
285286
v.iter()
@@ -317,7 +318,7 @@ pub struct Context<'a, 'tcx: 'a> {
317318

318319
/// Level of lints for certain NodeIds, stored here because the body of
319320
/// the lint needs to run in trans.
320-
node_levels: RefCell<HashMap<(ast::NodeId, LintId), LevelSource>>,
321+
node_levels: RefCell<FnvHashMap<(ast::NodeId, LintId), LevelSource>>,
321322
}
322323

323324
/// Convenience macro for calling a `LintPass` method on every pass in the context.
@@ -425,7 +426,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
425426
exported_items: exported_items,
426427
lints: lint_store,
427428
level_stack: vec![],
428-
node_levels: RefCell::new(HashMap::new()),
429+
node_levels: RefCell::new(FnvHashMap::new()),
429430
}
430431
}
431432

src/librustc/metadata/creader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use metadata::decoder;
2121
use metadata::loader;
2222
use metadata::loader::CratePaths;
2323
use plugin::load::PluginMetadata;
24+
use util::nodemap::FnvHashMap;
2425

2526
use std::rc::Rc;
26-
use std::collections::HashMap;
2727
use std::collections::hash_map::{Occupied, Vacant};
2828
use syntax::ast;
2929
use syntax::abi;
@@ -85,7 +85,7 @@ fn dump_crates(cstore: &CStore) {
8585
}
8686

8787
fn warn_if_multiple_versions(diag: &SpanHandler, cstore: &CStore) {
88-
let mut map = HashMap::new();
88+
let mut map = FnvHashMap::new();
8989
cstore.iter_crate_data(|cnum, data| {
9090
match map.entry(data.name()) {
9191
Vacant(entry) => { entry.set(vec![cnum]); },

src/librustc/metadata/cstore.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
use back::svh::Svh;
1717
use metadata::decoder;
1818
use metadata::loader;
19+
use util::nodemap::{FnvHashMap, NodeMap};
1920

2021
use std::cell::RefCell;
2122
use std::c_vec::CVec;
2223
use std::rc::Rc;
23-
use std::collections::HashMap;
2424
use syntax::ast;
2525
use syntax::codemap::Span;
2626
use syntax::parse::token::IdentInterner;
@@ -29,7 +29,7 @@ use syntax::parse::token::IdentInterner;
2929
// local crate numbers (as generated during this session). Each external
3030
// crate may refer to types in other external crates, and each has their
3131
// own crate numbers.
32-
pub type cnum_map = HashMap<ast::CrateNum, ast::CrateNum>;
32+
pub type cnum_map = FnvHashMap<ast::CrateNum, ast::CrateNum>;
3333

3434
pub enum MetadataBlob {
3535
MetadataVec(CVec<u8>),
@@ -67,22 +67,20 @@ pub struct CrateSource {
6767
}
6868

6969
pub struct CStore {
70-
metas: RefCell<HashMap<ast::CrateNum, Rc<crate_metadata>>>,
71-
extern_mod_crate_map: RefCell<extern_mod_crate_map>,
70+
metas: RefCell<FnvHashMap<ast::CrateNum, Rc<crate_metadata>>>,
71+
/// Map from NodeId's of local extern crate statements to crate numbers
72+
extern_mod_crate_map: RefCell<NodeMap<ast::CrateNum>>,
7273
used_crate_sources: RefCell<Vec<CrateSource>>,
7374
used_libraries: RefCell<Vec<(String, NativeLibaryKind)>>,
7475
used_link_args: RefCell<Vec<String>>,
7576
pub intr: Rc<IdentInterner>,
7677
}
7778

78-
// Map from NodeId's of local extern crate statements to crate numbers
79-
type extern_mod_crate_map = HashMap<ast::NodeId, ast::CrateNum>;
80-
8179
impl CStore {
8280
pub fn new(intr: Rc<IdentInterner>) -> CStore {
8381
CStore {
84-
metas: RefCell::new(HashMap::new()),
85-
extern_mod_crate_map: RefCell::new(HashMap::new()),
82+
metas: RefCell::new(FnvHashMap::new()),
83+
extern_mod_crate_map: RefCell::new(FnvHashMap::new()),
8684
used_crate_sources: RefCell::new(Vec::new()),
8785
used_libraries: RefCell::new(Vec::new()),
8886
used_link_args: RefCell::new(Vec::new()),

src/librustc/metadata/encoder.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ use middle::ty::{lookup_item_type};
2323
use middle::ty;
2424
use middle::stability;
2525
use middle;
26-
use util::nodemap::{NodeMap, NodeSet};
26+
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
2727

2828
use serialize::Encodable;
2929
use std::cell::RefCell;
3030
use std::hash::Hash;
3131
use std::hash;
32-
use std::collections::HashMap;
3332
use syntax::abi;
3433
use syntax::ast::*;
3534
use syntax::ast;
@@ -2062,7 +2061,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter, parms: EncodeParams, krate:
20622061
link_meta: link_meta,
20632062
cstore: cstore,
20642063
encode_inlined_item: RefCell::new(encode_inlined_item),
2065-
type_abbrevs: RefCell::new(HashMap::new()),
2064+
type_abbrevs: RefCell::new(FnvHashMap::new()),
20662065
reachable: reachable,
20672066
};
20682067

@@ -2167,7 +2166,7 @@ pub fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> String {
21672166
diag: tcx.sess.diagnostic(),
21682167
ds: def_to_string,
21692168
tcx: tcx,
2170-
abbrevs: &RefCell::new(HashMap::new())
2169+
abbrevs: &RefCell::new(FnvHashMap::new())
21712170
}, t);
21722171
String::from_utf8(wr.unwrap()).unwrap()
21732172
}

src/librustc/metadata/tyencode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#![allow(non_camel_case_types)]
1515

1616
use std::cell::RefCell;
17-
use std::collections::HashMap;
1817

1918
use middle::subst;
2019
use middle::subst::VecPerParamSpace;
2120
use middle::ty::ParamTy;
2221
use middle::ty;
22+
use util::nodemap::FnvHashMap;
2323

2424
use syntax::abi::Abi;
2525
use syntax::ast;
@@ -47,7 +47,7 @@ pub struct ty_abbrev {
4747
s: String
4848
}
4949

50-
pub type abbrev_map = RefCell<HashMap<ty::t, ty_abbrev>>;
50+
pub type abbrev_map = RefCell<FnvHashMap<ty::t, ty_abbrev>>;
5151

5252
pub fn enc_ty(w: &mut SeekableMemWriter, cx: &ctxt, t: ty::t) {
5353
match cx.abbrevs.borrow_mut().get(&t) {

src/librustc/middle/astencode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
11611161
})
11621162
}
11631163

1164-
for &ty in tcx.node_types.borrow().get(&(id as uint)).iter() {
1164+
for &ty in tcx.node_types.borrow().get(&id).iter() {
11651165
rbml_w.tag(c::tag_table_node_type, |rbml_w| {
11661166
rbml_w.id(id);
11671167
rbml_w.tag(c::tag_table_val, |rbml_w| {
@@ -1825,7 +1825,7 @@ fn decode_side_tables(dcx: &DecodeContext,
18251825
let ty = val_dsr.read_ty(dcx);
18261826
debug!("inserting ty for node {}: {}",
18271827
id, ty_to_string(dcx.tcx, ty));
1828-
dcx.tcx.node_types.borrow_mut().insert(id as uint, ty);
1828+
dcx.tcx.node_types.borrow_mut().insert(id, ty);
18291829
}
18301830
c::tag_table_item_subst => {
18311831
let item_substs = ty::ItemSubsts {

src/librustc/middle/borrowck/move_data.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ comments in the section "Moves and initialization" and in `doc.rs`.
1818
use std::cell::RefCell;
1919
use std::rc::Rc;
2020
use std::uint;
21-
use std::collections::{HashMap, HashSet};
2221
use middle::borrowck::*;
2322
use middle::cfg;
2423
use middle::dataflow::DataFlowContext;
@@ -30,14 +29,15 @@ use middle::ty;
3029
use syntax::ast;
3130
use syntax::ast_util;
3231
use syntax::codemap::Span;
32+
use util::nodemap::{FnvHashMap, NodeSet};
3333
use util::ppaux::Repr;
3434

3535
pub struct MoveData {
3636
/// Move paths. See section "Move paths" in `doc.rs`.
3737
pub paths: RefCell<Vec<MovePath>>,
3838

3939
/// Cache of loan path to move path index, for easy lookup.
40-
pub path_map: RefCell<HashMap<Rc<LoanPath>, MovePathIndex>>,
40+
pub path_map: RefCell<FnvHashMap<Rc<LoanPath>, MovePathIndex>>,
4141

4242
/// Each move or uninitialized variable gets an entry here.
4343
pub moves: RefCell<Vec<Move>>,
@@ -53,7 +53,7 @@ pub struct MoveData {
5353
pub path_assignments: RefCell<Vec<Assignment>>,
5454

5555
/// Assignments to a variable or path, like `x = foo`, but not `x += foo`.
56-
pub assignee_ids: RefCell<HashSet<ast::NodeId>>,
56+
pub assignee_ids: RefCell<NodeSet>,
5757
}
5858

5959
pub struct FlowedMoveData<'a, 'tcx: 'a> {
@@ -183,11 +183,11 @@ impl MoveData {
183183
pub fn new() -> MoveData {
184184
MoveData {
185185
paths: RefCell::new(Vec::new()),
186-
path_map: RefCell::new(HashMap::new()),
186+
path_map: RefCell::new(FnvHashMap::new()),
187187
moves: RefCell::new(Vec::new()),
188188
path_assignments: RefCell::new(Vec::new()),
189189
var_assignments: RefCell::new(Vec::new()),
190-
assignee_ids: RefCell::new(HashSet::new()),
190+
assignee_ids: RefCell::new(NodeSet::new()),
191191
}
192192
}
193193

src/librustc/middle/dependency_format.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@
6161
//! Additionally, the algorithm is geared towards finding *any* solution rather
6262
//! than finding a number of solutions (there are normally quite a few).
6363
64-
use std::collections::HashMap;
6564
use syntax::ast;
6665

6766
use driver::session;
6867
use driver::config;
6968
use metadata::cstore;
7069
use metadata::csearch;
7170
use middle::ty;
71+
use util::nodemap::FnvHashMap;
7272

7373
/// A list of dependencies for a certain crate type.
7474
///
@@ -81,7 +81,7 @@ pub type DependencyList = Vec<Option<cstore::LinkagePreference>>;
8181
/// A mapping of all required dependencies for a particular flavor of output.
8282
///
8383
/// This is local to the tcx, and is generally relevant to one session.
84-
pub type Dependencies = HashMap<config::CrateType, DependencyList>;
84+
pub type Dependencies = FnvHashMap<config::CrateType, DependencyList>;
8585

8686
pub fn calculate(tcx: &ty::ctxt) {
8787
let mut fmts = tcx.dependency_formats.borrow_mut();
@@ -137,7 +137,7 @@ fn calculate_type(sess: &session::Session,
137137
config::CrateTypeExecutable | config::CrateTypeDylib => {},
138138
}
139139

140-
let mut formats = HashMap::new();
140+
let mut formats = FnvHashMap::new();
141141

142142
// Sweep all crates for found dylibs. Add all dylibs, as well as their
143143
// dependencies, ensuring there are no conflicts. The only valid case for a
@@ -208,7 +208,7 @@ fn calculate_type(sess: &session::Session,
208208
fn add_library(sess: &session::Session,
209209
cnum: ast::CrateNum,
210210
link: cstore::LinkagePreference,
211-
m: &mut HashMap<ast::CrateNum, cstore::LinkagePreference>) {
211+
m: &mut FnvHashMap<ast::CrateNum, cstore::LinkagePreference>) {
212212
match m.get(&cnum) {
213213
Some(&link2) => {
214214
// If the linkages differ, then we'd have two copies of the library

src/librustc/middle/lang_items.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use driver::session::Session;
2424
use metadata::csearch::each_lang_item;
2525
use middle::ty;
2626
use middle::weak_lang_items;
27+
use util::nodemap::FnvHashMap;
28+
2729
use syntax::ast;
2830
use syntax::ast_util::local_def;
2931
use syntax::attr::AttrMetaMethods;
@@ -32,7 +34,6 @@ use syntax::parse::token::InternedString;
3234
use syntax::visit::Visitor;
3335
use syntax::visit;
3436

35-
use std::collections::HashMap;
3637
use std::iter::Enumerate;
3738
use std::slice;
3839

@@ -123,7 +124,7 @@ struct LanguageItemCollector<'a> {
123124

124125
session: &'a Session,
125126

126-
item_refs: HashMap<&'static str, uint>,
127+
item_refs: FnvHashMap<&'static str, uint>,
127128
}
128129

129130
impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> {
@@ -148,7 +149,7 @@ impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> {
148149

149150
impl<'a> LanguageItemCollector<'a> {
150151
pub fn new(session: &'a Session) -> LanguageItemCollector<'a> {
151-
let mut item_refs = HashMap::new();
152+
let mut item_refs = FnvHashMap::new();
152153

153154
$( item_refs.insert($name, $variant as uint); )*
154155

src/librustc/middle/pat_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
use middle::def::*;
1212
use middle::resolve;
1313
use middle::ty;
14+
use util::nodemap::FnvHashMap;
1415

15-
use std::collections::HashMap;
1616
use syntax::ast::*;
1717
use syntax::ast_util::{walk_pat};
1818
use syntax::codemap::{Span, DUMMY_SP};
1919

20-
pub type PatIdMap = HashMap<Ident, NodeId>;
20+
pub type PatIdMap = FnvHashMap<Ident, NodeId>;
2121

2222
// This is used because same-named variables in alternative patterns need to
2323
// use the NodeId of their namesake in the first pattern.
2424
pub fn pat_id_map(dm: &resolve::DefMap, pat: &Pat) -> PatIdMap {
25-
let mut map = HashMap::new();
25+
let mut map = FnvHashMap::new();
2626
pat_bindings(dm, pat, |_bm, p_id, _s, path1| {
2727
map.insert(path1.node, p_id);
2828
});

0 commit comments

Comments
 (0)