Skip to content

Commit 6f812fe

Browse files
committed
rustc: Remove uses of oldmap::HashMap
1 parent 31f6e64 commit 6f812fe

Some content is hidden

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

62 files changed

+877
-879
lines changed

src/librustc/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ pub fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t,
642642
643643
pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {
644644
match ccx.type_hashcodes.find(&t) {
645-
Some(h) => h,
645+
Some(&h) => h,
646646
None => {
647647
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
648648
ccx.type_hashcodes.insert(t, hash);

src/librustc/driver/driver.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ pub fn compile_rest(sess: Session, cfg: ast::crate_cfg,
246246

247247
// These next two const passes can probably be merged
248248
time(time_passes, ~"const marking", ||
249-
middle::const_eval::process_crate(crate, def_map, ty_cx));
249+
middle::const_eval::process_crate(crate, ty_cx));
250250

251251
time(time_passes, ~"const checking", ||
252252
middle::check_const::check_crate(sess, crate, ast_map, def_map,
@@ -546,11 +546,11 @@ pub fn build_session_options(+binary: ~str,
546546
let flags = vec::append(getopts::opt_strs(matches, level_short),
547547
getopts::opt_strs(matches, level_name));
548548
for flags.each |lint_name| {
549-
let lint_name = @str::replace(*lint_name, ~"-", ~"_");
549+
let lint_name = str::replace(*lint_name, ~"-", ~"_");
550550
match lint_dict.find(&lint_name) {
551551
None => {
552552
early_error(demitter, fmt!("unknown %s flag: %s",
553-
level_name, *lint_name));
553+
level_name, lint_name));
554554
}
555555
Some(lint) => {
556556
lint_opts.push((lint.lint, *level));

src/librustc/lib/llvm.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
use core::prelude::*;
1212

13+
use core::hashmap::linear::LinearMap;
1314
use core::libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
1415
use core::option;
1516
use core::ptr;
1617
use core::str;
1718
use core::vec;
18-
use std::oldmap::HashMap;
1919

2020
pub type Opcode = u32;
2121
pub type Bool = c_uint;
@@ -1467,8 +1467,8 @@ pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
14671467
/* Memory-managed object interface to type handles. */
14681468

14691469
pub struct TypeNames {
1470-
type_names: HashMap<TypeRef, @str>,
1471-
named_types: HashMap<@str, TypeRef>
1470+
type_names: @mut LinearMap<TypeRef, @str>,
1471+
named_types: @mut LinearMap<@str, TypeRef>
14721472
}
14731473

14741474
pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
@@ -1477,17 +1477,17 @@ pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
14771477
}
14781478

14791479
pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> {
1480-
return tn.type_names.find(&t);
1480+
return tn.type_names.find(&t).map_consume(|x| *x);
14811481
}
14821482

14831483
pub fn name_has_type(tn: @TypeNames, s: @str) -> Option<TypeRef> {
1484-
return tn.named_types.find(&s);
1484+
return tn.named_types.find(&s).map_consume(|x| *x);
14851485
}
14861486

14871487
pub fn mk_type_names() -> @TypeNames {
14881488
@TypeNames {
1489-
type_names: HashMap(),
1490-
named_types: HashMap()
1489+
type_names: @mut LinearMap::new(),
1490+
named_types: @mut LinearMap::new()
14911491
}
14921492
}
14931493

src/librustc/metadata/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ use metadata::filesearch::FileSearch;
1919
use metadata::loader;
2020

2121
use core::either;
22+
use core::hashmap::linear::LinearMap;
2223
use core::vec;
2324
use syntax::attr;
2425
use syntax::codemap::{span, dummy_sp};
2526
use syntax::diagnostic::span_handler;
2627
use syntax::parse::token::ident_interner;
2728
use syntax::visit;
2829
use syntax::{ast, ast_util};
29-
use std::oldmap::HashMap;
3030

3131
// Traverses an AST, reading all the information about use'd crates and extern
3232
// libraries necessary for later resolving, typechecking, linking, etc.
@@ -307,7 +307,7 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
307307
debug!("resolving deps of external crate");
308308
// The map from crate numbers in the crate we're resolving to local crate
309309
// numbers
310-
let cnum_map = HashMap();
310+
let mut cnum_map = LinearMap::new();
311311
for decoder::get_crate_deps(e.intr, cdata).each |dep| {
312312
let extrn_cnum = dep.cnum;
313313
let cname = dep.name;
@@ -334,7 +334,7 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
334334
}
335335
}
336336
}
337-
return cnum_map;
337+
return @mut cnum_map;
338338
}
339339

340340
// Local Variables:

src/librustc/metadata/cstore.rs

+27-36
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use core::prelude::*;
1717
use metadata::cstore;
1818
use metadata::decoder;
1919

20+
use core::hashmap::linear::LinearMap;
2021
use core::vec;
21-
use std::oldmap;
2222
use std;
2323
use syntax::{ast, attr};
2424
use syntax::parse::token::ident_interner;
@@ -27,7 +27,7 @@ use syntax::parse::token::ident_interner;
2727
// local crate numbers (as generated during this session). Each external
2828
// crate may refer to types in other external crates, and each has their
2929
// own crate numbers.
30-
pub type cnum_map = oldmap::HashMap<ast::crate_num, ast::crate_num>;
30+
pub type cnum_map = @mut LinearMap<ast::crate_num, ast::crate_num>;
3131

3232
pub struct crate_metadata {
3333
name: @~str,
@@ -37,7 +37,7 @@ pub struct crate_metadata {
3737
}
3838

3939
pub struct CStore {
40-
priv metas: oldmap::HashMap<ast::crate_num, @crate_metadata>,
40+
priv metas: LinearMap <ast::crate_num, @crate_metadata>,
4141
priv extern_mod_crate_map: extern_mod_crate_map,
4242
priv used_crate_files: ~[Path],
4343
priv used_libraries: ~[~str],
@@ -46,111 +46,102 @@ pub struct CStore {
4646
}
4747

4848
// Map from node_id's of local extern mod statements to crate numbers
49-
type extern_mod_crate_map = oldmap::HashMap<ast::node_id, ast::crate_num>;
49+
type extern_mod_crate_map = LinearMap<ast::node_id, ast::crate_num>;
5050

5151
pub fn mk_cstore(intr: @ident_interner) -> CStore {
52-
let meta_cache = oldmap::HashMap();
53-
let crate_map = oldmap::HashMap();
5452
return CStore {
55-
metas: meta_cache,
56-
extern_mod_crate_map: crate_map,
53+
metas: LinearMap::new(),
54+
extern_mod_crate_map: LinearMap::new(),
5755
used_crate_files: ~[],
5856
used_libraries: ~[],
5957
used_link_args: ~[],
6058
intr: intr
6159
};
6260
}
6361

64-
pub fn get_crate_data(cstore: @mut CStore, cnum: ast::crate_num)
62+
pub fn get_crate_data(cstore: &CStore, cnum: ast::crate_num)
6563
-> @crate_metadata {
66-
return cstore.metas.get(&cnum);
64+
return *cstore.metas.get(&cnum);
6765
}
6866

69-
pub fn get_crate_hash(cstore: @mut CStore, cnum: ast::crate_num) -> @~str {
67+
pub fn get_crate_hash(cstore: &CStore, cnum: ast::crate_num) -> @~str {
7068
let cdata = get_crate_data(cstore, cnum);
7169
decoder::get_crate_hash(cdata.data)
7270
}
7371

74-
pub fn get_crate_vers(cstore: @mut CStore, cnum: ast::crate_num) -> @~str {
72+
pub fn get_crate_vers(cstore: &CStore, cnum: ast::crate_num) -> @~str {
7573
let cdata = get_crate_data(cstore, cnum);
7674
decoder::get_crate_vers(cdata.data)
7775
}
7876

79-
pub fn set_crate_data(cstore: @mut CStore,
77+
pub fn set_crate_data(cstore: &mut CStore,
8078
cnum: ast::crate_num,
8179
data: @crate_metadata) {
82-
let metas = cstore.metas;
83-
metas.insert(cnum, data);
80+
cstore.metas.insert(cnum, data);
8481
}
8582

86-
pub fn have_crate_data(cstore: @mut CStore, cnum: ast::crate_num) -> bool {
83+
pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool {
8784
cstore.metas.contains_key(&cnum)
8885
}
8986

90-
pub fn iter_crate_data(cstore: @mut CStore,
87+
pub fn iter_crate_data(cstore: &CStore,
9188
i: &fn(ast::crate_num, @crate_metadata)) {
92-
let metas = cstore.metas;
93-
for metas.each |&k, &v| {
89+
for cstore.metas.each |&(&k, &v)| {
9490
i(k, v);
9591
}
9692
}
9793

98-
pub fn add_used_crate_file(cstore: @mut CStore, lib: &Path) {
99-
let cstore = &mut *cstore;
94+
pub fn add_used_crate_file(cstore: &mut CStore, lib: &Path) {
10095
if !vec::contains(cstore.used_crate_files, lib) {
10196
cstore.used_crate_files.push(copy *lib);
10297
}
10398
}
10499

105-
pub fn get_used_crate_files(cstore: @mut CStore) -> ~[Path] {
100+
pub fn get_used_crate_files(cstore: &CStore) -> ~[Path] {
106101
return /*bad*/copy cstore.used_crate_files;
107102
}
108103

109-
pub fn add_used_library(cstore: @mut CStore, lib: @~str) -> bool {
104+
pub fn add_used_library(cstore: &mut CStore, lib: @~str) -> bool {
110105
fail_unless!(*lib != ~"");
111106

112-
let cstore = &mut *cstore;
113107
if cstore.used_libraries.contains(&*lib) { return false; }
114108
cstore.used_libraries.push(/*bad*/ copy *lib);
115109
true
116110
}
117111

118-
pub fn get_used_libraries(cstore: @mut CStore) -> ~[~str] {
112+
pub fn get_used_libraries(cstore: &CStore) -> ~[~str] {
119113
/*bad*/copy cstore.used_libraries
120114
}
121115

122-
pub fn add_used_link_args(cstore: @mut CStore, args: &str) {
116+
pub fn add_used_link_args(cstore: &mut CStore, args: &str) {
123117
for args.each_split_char(' ') |s| {
124118
cstore.used_link_args.push(s.to_owned());
125119
}
126120
}
127121

128-
pub fn get_used_link_args(cstore: @mut CStore) -> ~[~str] {
122+
pub fn get_used_link_args(cstore: &CStore) -> ~[~str] {
129123
/*bad*/copy cstore.used_link_args
130124
}
131125

132-
pub fn add_extern_mod_stmt_cnum(cstore: @mut CStore,
126+
pub fn add_extern_mod_stmt_cnum(cstore: &mut CStore,
133127
emod_id: ast::node_id,
134128
cnum: ast::crate_num) {
135-
let extern_mod_crate_map = cstore.extern_mod_crate_map;
136-
extern_mod_crate_map.insert(emod_id, cnum);
129+
cstore.extern_mod_crate_map.insert(emod_id, cnum);
137130
}
138131

139-
pub fn find_extern_mod_stmt_cnum(cstore: @mut CStore,
132+
pub fn find_extern_mod_stmt_cnum(cstore: &CStore,
140133
emod_id: ast::node_id)
141134
-> Option<ast::crate_num> {
142-
let extern_mod_crate_map = cstore.extern_mod_crate_map;
143-
extern_mod_crate_map.find(&emod_id)
135+
cstore.extern_mod_crate_map.find(&emod_id).map_consume(|x| *x)
144136
}
145137

146138
// returns hashes of crates directly used by this crate. Hashes are sorted by
147139
// (crate name, crate version, crate hash) in lexicographic order (not semver)
148-
pub fn get_dep_hashes(cstore: @mut CStore) -> ~[~str] {
140+
pub fn get_dep_hashes(cstore: &CStore) -> ~[~str] {
149141
struct crate_hash { name: @~str, vers: @~str, hash: @~str }
150142
let mut result = ~[];
151143

152-
let extern_mod_crate_map = cstore.extern_mod_crate_map;
153-
for extern_mod_crate_map.each_value |&cnum| {
144+
for cstore.extern_mod_crate_map.each_value |&cnum| {
154145
let cdata = cstore::get_crate_data(cstore, cnum);
155146
let hash = decoder::get_crate_hash(cdata.data);
156147
let vers = decoder::get_crate_vers(cdata.data);

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
11321132
}
11331133

11341134
match cdata.cnum_map.find(&did.crate) {
1135-
option::Some(n) => ast::def_id { crate: n, node: did.node },
1135+
option::Some(&n) => ast::def_id { crate: n, node: did.node },
11361136
option::None => fail!(~"didn't find a crate in the cnum_map")
11371137
}
11381138
}

0 commit comments

Comments
 (0)