Skip to content

Commit 3864d6d

Browse files
committed
std: Rename the hashmap constructors to conform to new standards
Instead of using the new_ prefix just name them after their type
1 parent 383a801 commit 3864d6d

Some content is hidden

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

43 files changed

+140
-143
lines changed

src/cargo/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fn configure(opts: options) -> cargo {
387387
result::err(e) { fail e }
388388
};
389389

390-
let sources = map::new_str_hash::<source>();
390+
let sources = map::str_hash::<source>();
391391
try_parse_sources(path::connect(syscargo, "sources.json"), sources);
392392
try_parse_sources(path::connect(syscargo, "local-sources.json"), sources);
393393
let c = {

src/libstd/ebml.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import core::option;
77
import option::{some, none};
88

99
export doc;
10-
11-
export new_doc;
1210
export doc_at;
1311
export maybe_get_doc;
1412
export get_doc;
@@ -64,7 +62,7 @@ fn vuint_at(data: [u8], start: uint) -> {val: uint, next: uint} {
6462
} else { #error("vint too big"); fail; }
6563
}
6664

67-
fn new_doc(data: @[u8]) -> doc {
65+
fn doc(data: @[u8]) -> doc {
6866
ret {data: data, start: 0u, end: vec::len::<u8>(*data)};
6967
}
7068

@@ -575,7 +573,7 @@ fn test_option_int() {
575573
let mbuf = io::mem_buffer();
576574
let ebml_w = ebml::writer(io::mem_buffer_writer(mbuf));
577575
serialize_0(ebml_w, v);
578-
let ebml_doc = ebml::new_doc(@io::mem_buffer_buf(mbuf));
576+
let ebml_doc = ebml::doc(@io::mem_buffer_buf(mbuf));
579577
let deser = ebml_deserializer(ebml_doc);
580578
let v1 = deserialize_0(deser);
581579
#debug["v1 == %?", v1];

src/libstd/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl parser for parser {
407407
self.bump();
408408
self.parse_whitespace();
409409

410-
let values = map::new_str_hash();
410+
let values = map::str_hash();
411411

412412
if self.ch == '}' {
413413
self.bump();
@@ -501,7 +501,7 @@ fn eq(value0: json, value1: json) -> bool {
501501
#[cfg(test)]
502502
mod tests {
503503
fn mk_dict(items: [(str, json)]) -> json {
504-
let d = map::new_str_hash();
504+
let d = map::str_hash();
505505

506506
vec::iter(items) { |item|
507507
let (key, value) = item;

src/libstd/map.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#[doc = "A map type"];
22

33
import chained::hashmap;
4-
export hashmap, hashfn, eqfn, set, map, chained, new_hashmap, new_str_hash;
5-
export new_bytes_hash, new_int_hash, new_uint_hash, set_add;
4+
export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash;
5+
export bytes_hash, int_hash, uint_hash, set_add;
66

77
#[doc = "
88
A function that returns a hash of a value
@@ -289,7 +289,7 @@ mod chained {
289289
}
290290

291291
/*
292-
Function: new_hashmap
292+
Function: hashmap
293293
294294
Construct a hashmap.
295295
@@ -298,33 +298,33 @@ Parameters:
298298
hasher - The hash function for key type K
299299
eqer - The equality function for key type K
300300
*/
301-
fn new_hashmap<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>)
301+
fn hashmap<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>)
302302
-> hashmap<K, V> {
303303
chained::mk(hasher, eqer)
304304
}
305305

306306
#[doc = "Construct a hashmap for string keys"]
307-
fn new_str_hash<V: copy>() -> hashmap<str, V> {
308-
ret new_hashmap(str::hash, str::eq);
307+
fn str_hash<V: copy>() -> hashmap<str, V> {
308+
ret hashmap(str::hash, str::eq);
309309
}
310310

311311
#[doc = "Construct a hashmap for byte string keys"]
312-
fn new_bytes_hash<V: copy>() -> hashmap<[u8], V> {
313-
ret new_hashmap(vec::u8::hash, vec::u8::eq);
312+
fn bytes_hash<V: copy>() -> hashmap<[u8], V> {
313+
ret hashmap(vec::u8::hash, vec::u8::eq);
314314
}
315315

316316
#[doc = "Construct a hashmap for int keys"]
317-
fn new_int_hash<V: copy>() -> hashmap<int, V> {
317+
fn int_hash<V: copy>() -> hashmap<int, V> {
318318
fn hash_int(&&x: int) -> uint { int::hash(x) }
319319
fn eq_int(&&a: int, &&b: int) -> bool { ret a == b; }
320-
ret new_hashmap(hash_int, eq_int);
320+
ret hashmap(hash_int, eq_int);
321321
}
322322

323323
#[doc = "Construct a hashmap for uint keys"]
324-
fn new_uint_hash<V: copy>() -> hashmap<uint, V> {
324+
fn uint_hash<V: copy>() -> hashmap<uint, V> {
325325
fn hash_uint(&&x: uint) -> uint { uint::hash(x) }
326326
fn eq_uint(&&a: uint, &&b: uint) -> bool { ret a == b; }
327-
ret new_hashmap(hash_uint, eq_uint);
327+
ret hashmap(hash_uint, eq_uint);
328328
}
329329

330330
#[doc = "
@@ -346,7 +346,7 @@ mod tests {
346346
let eqer_str: map::eqfn<str> = str::eq;
347347
#debug("uint -> uint");
348348
let hm_uu: map::hashmap<uint, uint> =
349-
map::new_hashmap::<uint, uint>(hasher_uint, eqer_uint);
349+
map::hashmap::<uint, uint>(hasher_uint, eqer_uint);
350350
assert (hm_uu.insert(10u, 12u));
351351
assert (hm_uu.insert(11u, 13u));
352352
assert (hm_uu.insert(12u, 14u));
@@ -362,7 +362,7 @@ mod tests {
362362
let twelve: str = "twelve";
363363
#debug("str -> uint");
364364
let hm_su: map::hashmap<str, uint> =
365-
map::new_hashmap::<str, uint>(hasher_str, eqer_str);
365+
map::hashmap::<str, uint>(hasher_str, eqer_str);
366366
assert (hm_su.insert("ten", 12u));
367367
assert (hm_su.insert(eleven, 13u));
368368
assert (hm_su.insert("twelve", 14u));
@@ -376,7 +376,7 @@ mod tests {
376376
assert (hm_su.get("twelve") == 12u);
377377
#debug("uint -> str");
378378
let hm_us: map::hashmap<uint, str> =
379-
map::new_hashmap::<uint, str>(hasher_uint, eqer_uint);
379+
map::hashmap::<uint, str>(hasher_uint, eqer_uint);
380380
assert (hm_us.insert(10u, "twelve"));
381381
assert (hm_us.insert(11u, "thirteen"));
382382
assert (hm_us.insert(12u, "fourteen"));
@@ -389,7 +389,7 @@ mod tests {
389389
assert (str::eq(hm_us.get(12u), "twelve"));
390390
#debug("str -> str");
391391
let hm_ss: map::hashmap<str, str> =
392-
map::new_hashmap::<str, str>(hasher_str, eqer_str);
392+
map::hashmap::<str, str>(hasher_str, eqer_str);
393393
assert (hm_ss.insert(ten, "twelve"));
394394
assert (hm_ss.insert(eleven, "thirteen"));
395395
assert (hm_ss.insert(twelve, "fourteen"));
@@ -417,7 +417,7 @@ mod tests {
417417
let hasher_uint: map::hashfn<uint> = uint_id;
418418
let eqer_uint: map::eqfn<uint> = eq_uint;
419419
let hm_uu: map::hashmap<uint, uint> =
420-
map::new_hashmap::<uint, uint>(hasher_uint, eqer_uint);
420+
map::hashmap::<uint, uint>(hasher_uint, eqer_uint);
421421
let i: uint = 0u;
422422
while i < num_to_insert {
423423
assert (hm_uu.insert(i, i * i));
@@ -444,7 +444,7 @@ mod tests {
444444
let hasher_str: map::hashfn<str> = str::hash;
445445
let eqer_str: map::eqfn<str> = str::eq;
446446
let hm_ss: map::hashmap<str, str> =
447-
map::new_hashmap::<str, str>(hasher_str, eqer_str);
447+
map::hashmap::<str, str>(hasher_str, eqer_str);
448448
i = 0u;
449449
while i < num_to_insert {
450450
assert hm_ss.insert(uint::to_str(i, 2u), uint::to_str(i * i, 2u));
@@ -497,7 +497,7 @@ mod tests {
497497
let hasher: map::hashfn<uint> = hash;
498498
let eqer: map::eqfn<uint> = eq;
499499
let hm: map::hashmap<uint, uint> =
500-
map::new_hashmap::<uint, uint>(hasher, eqer);
500+
map::hashmap::<uint, uint>(hasher, eqer);
501501
let i: uint = 0u;
502502
while i < num_to_insert {
503503
assert (hm.insert(i, i * i));
@@ -560,7 +560,7 @@ mod tests {
560560
#[test]
561561
fn test_contains_key() {
562562
let key = "k";
563-
let map = map::new_hashmap::<str, str>(str::hash, str::eq);
563+
let map = map::hashmap::<str, str>(str::hash, str::eq);
564564
assert (!map.contains_key(key));
565565
map.insert(key, "val");
566566
assert (map.contains_key(key));
@@ -569,7 +569,7 @@ mod tests {
569569
#[test]
570570
fn test_find() {
571571
let key = "k";
572-
let map = map::new_hashmap::<str, str>(str::hash, str::eq);
572+
let map = map::hashmap::<str, str>(str::hash, str::eq);
573573
assert (option::is_none(map.find(key)));
574574
map.insert(key, "val");
575575
assert (option::get(map.find(key)) == "val");

src/libstd/uv.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ fn loop_new() -> uv_loop unsafe {
131131

132132
// all state goes here
133133
let handles: map::hashmap<[u8], *libc::c_void> =
134-
map::new_bytes_hash();
134+
map::bytes_hash();
135135
let id_to_handle: map::hashmap<[u8], uv_handle> =
136-
map::new_bytes_hash();
136+
map::bytes_hash();
137137
let after_cbs: map::hashmap<[u8], fn~(uv_handle)> =
138-
map::new_bytes_hash();
138+
map::bytes_hash();
139139
let close_callbacks: map::hashmap<[u8], fn~()> =
140-
map::new_bytes_hash();
140+
map::bytes_hash();
141141
let async_cbs: map::hashmap<[u8], fn~(uv_handle)> =
142-
map::new_bytes_hash();
142+
map::bytes_hash();
143143
let timer_cbs: map::hashmap<[u8], fn~(uv_handle)> =
144-
map::new_bytes_hash();
144+
map::bytes_hash();
145145

146146
// the main loop that this task blocks on.
147147
// should have the same lifetime as the C libuv

src/rustc/back/rpath.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn get_install_prefix_rpath(cwd: path::path, target_triple: str) -> str {
178178
}
179179

180180
fn minimize_rpaths(rpaths: [str]) -> [str] {
181-
let set = map::new_str_hash::<()>();
181+
let set = map::str_hash::<()>();
182182
let minimized = [];
183183
for rpath in rpaths {
184184
if !set.contains_key(rpath) {

src/rustc/front/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) ->
220220
}
221221

222222
fn require_unique_names(sess: session, metas: [@ast::meta_item]) {
223-
let map = map::new_str_hash();
223+
let map = map::str_hash();
224224
for meta: @ast::meta_item in metas {
225225
let name = get_meta_item_name(meta);
226226
if map.contains_key(name) {

src/rustc/lib/llvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,8 @@ fn name_has_type(tn: type_names, s: str) -> option<TypeRef> {
940940
fn mk_type_names() -> type_names {
941941
fn hash(&&t: TypeRef) -> uint { ret t as uint; }
942942
fn eq(&&a: TypeRef, &&b: TypeRef) -> bool { ret a as uint == b as uint; }
943-
@{type_names: std::map::new_hashmap(hash, eq),
944-
named_types: std::map::new_str_hash()}
943+
@{type_names: std::map::hashmap(hash, eq),
944+
named_types: std::map::str_hash()}
945945
}
946946

947947
fn type_to_str(names: type_names, ty: TypeRef) -> str {

src/rustc/metadata/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ fn roundtrip(in_item: @ast::item) {
951951
let mbuf = io::mem_buffer();
952952
let ebml_w = ebml::writer(io::mem_buffer_writer(mbuf));
953953
encode_item_ast(ebml_w, in_item);
954-
let ebml_doc = ebml::new_doc(@io::mem_buffer_buf(mbuf));
954+
let ebml_doc = ebml::doc(@io::mem_buffer_buf(mbuf));
955955
let out_item = decode_item_ast(ebml_doc);
956956
#debug["out_item = %s", pprust::item_to_str(out_item)];
957957
assert in_item == out_item;

src/rustc/metadata/creader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import syntax::visit;
99
import syntax::codemap::span;
1010
import util::{filesearch};
1111
import io::writer_util;
12-
import std::map::{hashmap, new_int_hash};
12+
import std::map::{hashmap, int_hash};
1313
import syntax::print::pprust;
1414
import common::*;
1515

@@ -20,7 +20,7 @@ export list_file_metadata;
2020
// libraries necessary for later resolving, typechecking, linking, etc.
2121
fn read_crates(sess: session::session, crate: ast::crate) {
2222
let e = @{sess: sess,
23-
crate_cache: std::map::new_str_hash::<int>(),
23+
crate_cache: std::map::str_hash::<int>(),
2424
mutable next_crate_num: 1};
2525
let v =
2626
visit::mk_simple_visitor(@{visit_view_item:
@@ -275,7 +275,7 @@ fn resolve_crate_deps(e: env, cdata: @[u8]) -> cstore::cnum_map {
275275
#debug("resolving deps of external crate");
276276
// The map from crate numbers in the crate we're resolving to local crate
277277
// numbers
278-
let cnum_map = new_int_hash::<ast::crate_num>();
278+
let cnum_map = int_hash::<ast::crate_num>();
279279
for dep: decoder::crate_dep in decoder::get_crate_deps(cdata) {
280280
let extrn_cnum = dep.cnum;
281281
let cname = dep.ident;

src/rustc/metadata/cstore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ type use_crate_map = map::hashmap<ast::node_id, ast::crate_num>;
6464
fn p(cstore: cstore) -> cstore_private { alt cstore { private(p) { p } } }
6565

6666
fn mk_cstore() -> cstore {
67-
let meta_cache = map::new_int_hash::<crate_metadata>();
68-
let crate_map = map::new_int_hash::<ast::crate_num>();
67+
let meta_cache = map::int_hash::<crate_metadata>();
68+
let crate_map = map::int_hash::<ast::crate_num>();
6969
let mod_path_map = new_def_hash();
7070
ret private(@{metas: meta_cache,
7171
use_crate_map: crate_map,

src/rustc/metadata/decoder.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn find_item(item_id: int, items: ebml::doc) -> ebml::doc {
8181
// Looks up an item in the given metadata and returns an ebml doc pointing
8282
// to the item data.
8383
fn lookup_item(item_id: int, data: @[u8]) -> ebml::doc {
84-
let items = ebml::get_doc(ebml::new_doc(data), tag_items);
84+
let items = ebml::get_doc(ebml::doc(data), tag_items);
8585
ret find_item(item_id, items);
8686
}
8787

@@ -169,7 +169,7 @@ fn resolve_path(path: [ast::ident], data: @[u8]) -> [ast::def_id] {
169169
ret str::eq(str::from_bytes(data), s);
170170
}
171171
let s = str::connect(path, "::");
172-
let md = ebml::new_doc(data);
172+
let md = ebml::doc(data);
173173
let paths = ebml::get_doc(md, tag_paths);
174174
let eqer = bind eq_item(_, s);
175175
let result: [ast::def_id] = [];
@@ -274,7 +274,7 @@ fn maybe_get_item_ast(cdata: cmd, tcx: ty::ctxt, maps: maps,
274274
fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
275275
-> [ty::variant_info] {
276276
let data = cdata.data;
277-
let items = ebml::get_doc(ebml::new_doc(data), tag_items);
277+
let items = ebml::get_doc(ebml::doc(data), tag_items);
278278
let item = find_item(id, items);
279279
let infos: [ty::variant_info] = [];
280280
let variant_ids = enum_variant_ids(item, cdata);
@@ -459,14 +459,14 @@ fn list_crate_attributes(md: ebml::doc, hash: str, out: io::writer) {
459459
}
460460

461461
fn get_crate_attributes(data: @[u8]) -> [ast::attribute] {
462-
ret get_attributes(ebml::new_doc(data));
462+
ret get_attributes(ebml::doc(data));
463463
}
464464

465465
type crate_dep = {cnum: ast::crate_num, ident: str};
466466

467467
fn get_crate_deps(data: @[u8]) -> [crate_dep] {
468468
let deps: [crate_dep] = [];
469-
let cratedoc = ebml::new_doc(data);
469+
let cratedoc = ebml::doc(data);
470470
let depsdoc = ebml::get_doc(cratedoc, tag_crate_deps);
471471
let crate_num = 1;
472472
ebml::tagged_docs(depsdoc, tag_crate_dep) {|depdoc|
@@ -488,7 +488,7 @@ fn list_crate_deps(data: @[u8], out: io::writer) {
488488
}
489489

490490
fn get_crate_hash(data: @[u8]) -> str {
491-
let cratedoc = ebml::new_doc(data);
491+
let cratedoc = ebml::doc(data);
492492
let hashdoc = ebml::get_doc(cratedoc, tag_crate_hash);
493493
ret str::from_bytes(ebml::doc_data(hashdoc));
494494
}
@@ -503,7 +503,7 @@ fn list_crate_items(bytes: @[u8], md: ebml::doc, out: io::writer) {
503503
}
504504

505505
fn iter_crate_items(bytes: @[u8], proc: fn(str, ast::def_id)) {
506-
let md = ebml::new_doc(bytes);
506+
let md = ebml::doc(bytes);
507507
let paths = ebml::get_doc(md, tag_paths);
508508
let index = ebml::get_doc(paths, tag_index);
509509
let bs = ebml::get_doc(index, tag_index_buckets);
@@ -527,7 +527,7 @@ fn get_crate_module_paths(bytes: @[u8]) -> [(ast::def_id, str)] {
527527
// find all module (path, def_ids), which are not
528528
// fowarded path due to renamed import or reexport
529529
let res = [];
530-
let mods = map::new_str_hash();
530+
let mods = map::str_hash();
531531
iter_crate_items(bytes) {|path, did|
532532
let m = mod_of_path(path);
533533
if str::is_not_empty(m) {
@@ -547,7 +547,7 @@ fn get_crate_module_paths(bytes: @[u8]) -> [(ast::def_id, str)] {
547547

548548
fn list_crate_metadata(bytes: @[u8], out: io::writer) {
549549
let hash = get_crate_hash(bytes);
550-
let md = ebml::new_doc(bytes);
550+
let md = ebml::doc(bytes);
551551
list_crate_attributes(md, hash, out);
552552
list_crate_deps(bytes, out);
553553
list_crate_items(bytes, md, out);

src/rustc/metadata/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type ctx = {ccx: @middle::trans::common::crate_ctxt,
2121

2222
fn find_reachable(ccx: @middle::trans::common::crate_ctxt, crate_mod: _mod)
2323
-> map {
24-
let rmap = std::map::new_int_hash();
24+
let rmap = std::map::int_hash();
2525
traverse_public_mod({ccx: ccx, rmap: rmap}, crate_mod);
2626
rmap
2727
}

src/rustc/middle/alias.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> (copy_map, ref_map) {
6262
// Stores information about function arguments that's otherwise not easily
6363
// available.
6464
let cx = @{tcx: tcx,
65-
copy_map: std::map::new_int_hash(),
66-
ref_map: std::map::new_int_hash(),
65+
copy_map: std::map::int_hash(),
66+
ref_map: std::map::int_hash(),
6767
mutable silent: false};
6868
let v = @{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _),
6969
visit_expr: bind visit_expr(cx, _, _, _),

0 commit comments

Comments
 (0)