Skip to content

Commit 1b4eb14

Browse files
committed
oldmap: implement core::container::Container
1 parent f4a27b2 commit 1b4eb14

File tree

7 files changed

+22
-18
lines changed

7 files changed

+22
-18
lines changed

src/libcargo/cargo.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ pub fn install_package(c: &Cargo, src: ~str, wd: &Path, pkg: Package) {
922922
}
923923

924924
pub fn cargo_suggestion(c: &Cargo, fallback: fn()) {
925-
if c.sources.size() == 0u {
925+
if c.sources.is_empty() {
926926
error(~"no sources defined - you may wish to run " +
927927
~"`cargo init`");
928928
return;
@@ -1620,7 +1620,7 @@ pub fn dump_cache(c: &Cargo) {
16201620
}
16211621

16221622
pub fn dump_sources(c: &Cargo) {
1623-
if c.sources.size() < 1u {
1623+
if c.sources.is_empty() {
16241624
return;
16251625
}
16261626

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2796,7 +2796,7 @@ pub fn decl_gc_metadata(ccx: @crate_ctxt, llmod_id: ~str) {
27962796
27972797
pub fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
27982798
let elttype = T_struct(~[ccx.int_type, ccx.int_type]);
2799-
let maptype = T_array(elttype, ccx.module_data.size() + 1u);
2799+
let maptype = T_array(elttype, ccx.module_data.len() + 1);
28002800
let map = str::as_c_str(~"_rust_mod_map", |buf| {
28012801
unsafe {
28022802
llvm::LLVMAddGlobal(ccx.llmod, maptype, buf)

src/librustc/middle/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,7 @@ pub fn br_hashmap<V:Copy>() -> HashMap<bound_region, V> {
27992799
}
28002800
28012801
pub fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t {
2802-
//io::println(fmt!("%?/%?", id, cx.node_types.size()));
2802+
//io::println(fmt!("%?/%?", id, cx.node_types.len()));
28032803
match oldsmallintmap::find(*cx.node_types, id as uint) {
28042804
Some(t) => t,
28052805
None => cx.sess.bug(
@@ -4359,7 +4359,7 @@ pub fn iter_bound_traits_and_supertraits(tcx: ctxt,
43594359
if f(trait_ty) {
43604360
// Add all the supertraits to the hash map,
43614361
// executing <f> on each of them
4362-
while i < supertrait_map.size() && !fin {
4362+
while i < supertrait_map.len() && !fin {
43634363
let init_trait_id = seen_def_ids[i];
43644364
i += 1;
43654365
// Add supertraits to supertrait_map

src/librustc/middle/typeck/infer/region_inference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ impl RegionVarBindings {
12261226

12271227
fn construct_graph(&self) -> Graph {
12281228
let num_vars = self.num_vars();
1229-
let num_edges = self.constraints.size();
1229+
let num_edges = self.constraints.len();
12301230

12311231
let nodes = vec::from_fn(num_vars, |var_idx| {
12321232
GraphNode {

src/librustdoc/astsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn srv_should_build_ast_map() {
164164
let source = ~"fn a() { }";
165165
do from_str(source) |srv| {
166166
do exec(srv) |ctxt| {
167-
assert ctxt.ast_map.size() != 0u
167+
assert !ctxt.ast_map.is_empty()
168168
};
169169
}
170170
}

src/libstd/oldmap.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! A map type - **deprecated**, use `core::hashmap` instead
1212
#[forbid(deprecated_mode)];
1313

14+
use core::container::{Container, Mutable, Map};
1415
use core::cmp::Eq;
1516
use core::hash::Hash;
1617
use core::io::WriterUtil;
@@ -161,9 +162,12 @@ pub mod chained {
161162
}
162163
}
163164

164-
impl<K:Eq IterBytes Hash Copy, V: Copy> T<K, V> {
165-
pure fn size() -> uint { self.count }
165+
impl<K: Eq IterBytes Hash, V> T<K, V>: Container {
166+
pure fn len(&self) -> uint { self.count }
167+
pure fn is_empty(&self) -> bool { self.count == 0 }
168+
}
166169

170+
impl<K:Eq IterBytes Hash Copy, V: Copy> T<K, V> {
167171
pure fn contains_key_ref(k: &K) -> bool {
168172
let hash = k.hash_keyed(0,0) as uint;
169173
match self.search_tbl(k, hash) {
@@ -404,7 +408,7 @@ pub fn set_add<K:Eq IterBytes Hash Const Copy>(set: Set<K>, key: K) -> bool {
404408

405409
/// Convert a set into a vector.
406410
pub pure fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
407-
do vec::build_sized(s.size()) |push| {
411+
do vec::build_sized(s.len()) |push| {
408412
for s.each_key() |k| {
409413
push(k);
410414
}
@@ -580,7 +584,7 @@ mod tests {
580584
debug!("inserting %u -> %u", i, i*i);
581585
i += 1u;
582586
}
583-
assert (hm.size() == num_to_insert);
587+
assert (hm.len() == num_to_insert);
584588
debug!("-----");
585589
debug!("removing evens");
586590
i = 0u;
@@ -589,7 +593,7 @@ mod tests {
589593
assert v;
590594
i += 2u;
591595
}
592-
assert (hm.size() == num_to_insert / 2u);
596+
assert (hm.len() == num_to_insert / 2u);
593597
debug!("-----");
594598
i = 1u;
595599
while i < num_to_insert {
@@ -611,7 +615,7 @@ mod tests {
611615
debug!("inserting %u -> %u", i, i*i);
612616
i += 2u;
613617
}
614-
assert (hm.size() == num_to_insert);
618+
assert (hm.len() == num_to_insert);
615619
debug!("-----");
616620
i = 0u;
617621
while i < num_to_insert {
@@ -620,7 +624,7 @@ mod tests {
620624
i += 1u;
621625
}
622626
debug!("-----");
623-
assert (hm.size() == num_to_insert);
627+
assert (hm.len() == num_to_insert);
624628
i = 0u;
625629
while i < num_to_insert {
626630
debug!("get(%u) = %u", i, hm.get(i));
@@ -653,10 +657,10 @@ mod tests {
653657
let key = ~"k";
654658
let map = HashMap::<~str, ~str>();
655659
map.insert(key, ~"val");
656-
assert (map.size() == 1);
660+
assert (map.len() == 1);
657661
assert (map.contains_key_ref(&key));
658662
map.clear();
659-
assert (map.size() == 0);
663+
assert (map.len() == 0);
660664
assert (!map.contains_key_ref(&key));
661665
}
662666

@@ -667,7 +671,7 @@ mod tests {
667671
(~"b", 2),
668672
(~"c", 3)
669673
]);
670-
assert map.size() == 3u;
674+
assert map.len() == 3u;
671675
assert map.get(~"a") == 1;
672676
assert map.get(~"b") == 2;
673677
assert map.get(~"c") == 3;

src/test/bench/graph500-bfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn gen_search_keys(graph: graph, n: uint) -> ~[node_id] {
102102
let keys = oldmap::HashMap::<node_id, ()>();
103103
let r = rand::Rng();
104104

105-
while keys.size() < n {
105+
while keys.len() < n {
106106
let k = r.gen_uint_range(0u, graph.len());
107107

108108
if graph[k].len() > 0u && vec::any(graph[k], |i| {

0 commit comments

Comments
 (0)