Skip to content

Commit 7f0fa14

Browse files
committed
switch LinearMap to current constructor convention
1 parent 591eefd commit 7f0fa14

File tree

6 files changed

+37
-33
lines changed

6 files changed

+37
-33
lines changed

src/libcargo/cargo.rc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ fn dump_cache(c: &Cargo) {
16171617
need_dir(&c.root);
16181618

16191619
let out = c.root.push("cache.json");
1620-
let _root = json::Object(~LinearMap());
1620+
let _root = json::Object(~LinearMap::new());
16211621

16221622
if os::path_exists(&out) {
16231623
copy_warn(&out, &c.root.push("cache.json.old"));
@@ -1638,10 +1638,10 @@ fn dump_sources(c: &Cargo) {
16381638

16391639
match io::buffered_file_writer(&out) {
16401640
result::Ok(writer) => {
1641-
let mut hash = ~LinearMap();
1641+
let mut hash = ~LinearMap::new();
16421642

16431643
for c.sources.each |k, v| {
1644-
let mut chash = ~LinearMap();
1644+
let mut chash = ~LinearMap::new();
16451645

16461646
chash.insert(~"url", json::String(v.url));
16471647
chash.insert(~"method", json::String(v.method));

src/libcore/hashmap.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ pub mod linear {
352352
}
353353

354354
impl<K:Hash IterBytes Eq,V> LinearMap<K,V> {
355+
static fn new() -> LinearMap<K, V> {
356+
linear_map_with_capacity(INITIAL_CAPACITY)
357+
}
358+
355359
fn pop(&mut self, k: &K) -> Option<V> {
356360
let hash = k.hash_keyed(self.k0, self.k1) as uint;
357361
self.pop_internal(hash, k)
@@ -405,7 +409,7 @@ pub mod linear {
405409
}
406410
}
407411

408-
impl<K:Hash IterBytes Eq, V: Copy> LinearMap<K,V> {
412+
impl<K:Hash IterBytes Eq, V: Copy> LinearMap<K, V> {
409413
pure fn find_copy(&const self, k: &K) -> Option<V> {
410414
match self.bucket_for_key(self.buckets, k) {
411415
FoundEntry(idx) => {
@@ -504,7 +508,7 @@ pub mod test {
504508

505509
#[test]
506510
pub fn inserts() {
507-
let mut m = ~LinearMap();
511+
let mut m = LinearMap::new();
508512
assert m.insert(1, 2);
509513
assert m.insert(2, 4);
510514
assert *m.get(&1) == 2;
@@ -513,7 +517,7 @@ pub mod test {
513517

514518
#[test]
515519
pub fn overwrite() {
516-
let mut m = ~LinearMap();
520+
let mut m = LinearMap::new();
517521
assert m.insert(1, 2);
518522
assert *m.get(&1) == 2;
519523
assert !m.insert(1, 3);
@@ -553,26 +557,26 @@ pub mod test {
553557

554558
#[test]
555559
pub fn pops() {
556-
let mut m = ~LinearMap();
560+
let mut m = LinearMap::new();
557561
m.insert(1, 2);
558562
assert m.pop(&1) == Some(2);
559563
assert m.pop(&1) == None;
560564
}
561565

562566
#[test]
563567
pub fn swaps() {
564-
let mut m = ~LinearMap();
568+
let mut m = LinearMap::new();
565569
assert m.swap(1, 2) == None;
566570
assert m.swap(1, 3) == Some(2);
567571
assert m.swap(1, 4) == Some(3);
568572
}
569573

570574
#[test]
571575
pub fn consumes() {
572-
let mut m = ~LinearMap();
576+
let mut m = LinearMap::new();
573577
assert m.insert(1, 2);
574578
assert m.insert(2, 3);
575-
let mut m2 = ~LinearMap();
579+
let mut m2 = LinearMap::new();
576580
do m.consume |k, v| {
577581
m2.insert(k, v);
578582
}
@@ -598,7 +602,7 @@ pub mod test {
598602

599603
#[test]
600604
pub fn find() {
601-
let mut m = ~LinearMap();
605+
let mut m = LinearMap::new();
602606
assert m.find(&1).is_none();
603607
m.insert(1, 2);
604608
match m.find(&1) {
@@ -609,12 +613,12 @@ pub mod test {
609613

610614
#[test]
611615
pub fn test_eq() {
612-
let mut m1 = ~LinearMap();
616+
let mut m1 = LinearMap::new();
613617
m1.insert(1, 2);
614618
m1.insert(2, 3);
615619
m1.insert(3, 4);
616620

617-
let mut m2 = ~LinearMap();
621+
let mut m2 = LinearMap::new();
618622
m2.insert(1, 2);
619623
m2.insert(2, 3);
620624

@@ -627,7 +631,7 @@ pub mod test {
627631

628632
#[test]
629633
pub fn test_expand() {
630-
let mut m = ~LinearMap();
634+
let mut m = LinearMap::new();
631635

632636
assert m.len() == 0;
633637
assert m.is_empty();

src/libstd/json.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use core::float;
2424
use core::io::{WriterUtil, ReaderUtil};
2525
use core::io;
2626
use core::prelude::*;
27-
use core::hashmap::linear;
27+
use core::hashmap::linear::LinearMap;
2828
use core::str;
2929
use core::to_str;
3030
use core::vec;
@@ -40,7 +40,7 @@ pub enum Json {
4040
}
4141

4242
pub type List = ~[Json];
43-
pub type Object = linear::LinearMap<~str, Json>;
43+
pub type Object = LinearMap<~str, Json>;
4444

4545
pub struct Error {
4646
line: uint,
@@ -671,7 +671,7 @@ priv impl Parser {
671671
self.bump();
672672
self.parse_whitespace();
673673

674-
let mut values = ~linear::LinearMap();
674+
let mut values = ~LinearMap::new();
675675

676676
if self.ch == '}' {
677677
self.bump();
@@ -1175,9 +1175,9 @@ impl <A: ToJson> ~[A]: ToJson {
11751175
fn to_json() -> Json { List(self.map(|elt| elt.to_json())) }
11761176
}
11771177

1178-
impl <A: ToJson Copy> linear::LinearMap<~str, A>: ToJson {
1178+
impl <A: ToJson Copy> LinearMap<~str, A>: ToJson {
11791179
fn to_json() -> Json {
1180-
let mut d = linear::LinearMap();
1180+
let mut d = LinearMap::new();
11811181
for self.each() |key, value| {
11821182
d.insert(copy *key, value.to_json());
11831183
}
@@ -1188,7 +1188,7 @@ impl <A: ToJson Copy> linear::LinearMap<~str, A>: ToJson {
11881188
/*
11891189
impl <A: ToJson Copy> @std::map::HashMap<~str, A>: ToJson {
11901190
fn to_json() -> Json {
1191-
let mut d = linear::LinearMap();
1191+
let mut d = LinearMap::new();
11921192
for self.each_ref |key, value| {
11931193
d.insert(copy *key, value.to_json());
11941194
}
@@ -1223,10 +1223,10 @@ mod tests {
12231223
use json::*;
12241224

12251225
use core::result;
1226-
use core::hashmap::linear;
1226+
use core::hashmap::linear::LinearMap;
12271227

12281228
fn mk_object(items: &[(~str, Json)]) -> Json {
1229-
let mut d = ~linear::LinearMap();
1229+
let mut d = LinearMap::new();
12301230

12311231
for items.each |item| {
12321232
match *item {

src/libstd/net_url.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub fn encode_form_urlencoded(m: &LinearMap<~str, ~[~str]>) -> ~str {
242242
*/
243243
pub fn decode_form_urlencoded(s: &[u8]) -> LinearMap<~str, ~[~str]> {
244244
do io::with_bytes_reader(s) |rdr| {
245-
let mut m = LinearMap();
245+
let mut m = LinearMap::new();
246246
let mut key = ~"";
247247
let mut value = ~"";
248248
let mut parsing_key = true;
@@ -1053,18 +1053,18 @@ mod tests {
10531053

10541054
#[test]
10551055
fn test_encode_form_urlencoded() {
1056-
let mut m = LinearMap();
1056+
let mut m = LinearMap::new();
10571057
assert encode_form_urlencoded(&m) == ~"";
10581058

10591059
m.insert(~"", ~[]);
10601060
m.insert(~"foo", ~[]);
10611061
assert encode_form_urlencoded(&m) == ~"";
10621062

1063-
let mut m = LinearMap();
1063+
let mut m = LinearMap::new();
10641064
m.insert(~"foo", ~[~"bar", ~"123"]);
10651065
assert encode_form_urlencoded(&m) == ~"foo=bar&foo=123";
10661066

1067-
let mut m = LinearMap();
1067+
let mut m = LinearMap::new();
10681068
m.insert(~"foo bar", ~[~"abc", ~"12 = 34"]);
10691069
assert encode_form_urlencoded(&m) == ~"foo+bar=abc&foo+bar=12+%3D+34";
10701070
}

src/libstd/workcache.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub impl<S: Encoder> WorkMap: Encodable<S> {
152152
pub impl<D: Decoder> WorkMap: Decodable<D> {
153153
static fn decode(&self, d: &D) -> WorkMap {
154154
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
155-
let mut w = LinearMap();
155+
let mut w = LinearMap::new();
156156
for v.each |&(k,v)| {
157157
w.insert(copy k, copy v);
158158
}
@@ -348,8 +348,8 @@ impl @Mut<Prep> : TPrep {
348348
let blk = blk.unwrap();
349349
let chan = ~mut Some(move chan);
350350
do task::spawn |move blk, move chan| {
351-
let exe = Exec { discovered_inputs: LinearMap(),
352-
discovered_outputs: LinearMap() };
351+
let exe = Exec{discovered_inputs: LinearMap::new(),
352+
discovered_outputs: LinearMap::new()};
353353
let chan = option::swap_unwrap(&mut *chan);
354354
let v = blk(&exe);
355355
send_one(move chan, (move exe, move v));
@@ -411,10 +411,10 @@ fn test() {
411411
use io::WriterUtil;
412412

413413
let db = @Mut(Database { db_filename: Path("db.json"),
414-
db_cache: LinearMap(),
414+
db_cache: LinearMap::new(),
415415
db_dirty: false });
416416
let lg = @Mut(Logger { a: () });
417-
let cfg = @LinearMap();
417+
let cfg = @LinearMap::new();
418418
let cx = @Context::new(db, lg, cfg);
419419
let w:Work<~str> = do cx.prep("test1") |prep| {
420420
let pth = Path("foo.c");

src/test/bench/core-map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ fn main() {
178178
let rng = rand::seeded_rng(&seed);
179179
let mut results = empty_results();
180180
int_benchmarks::<@Mut<LinearMap<uint, uint>>>(
181-
|| @Mut(LinearMap()),
181+
|| @Mut(LinearMap::new()),
182182
rng, num_keys, &mut results);
183183
str_benchmarks::<@Mut<LinearMap<~str, uint>>>(
184-
|| @Mut(LinearMap()),
184+
|| @Mut(LinearMap::new()),
185185
rng, num_keys, &mut results);
186186
write_results("libstd::map::hashmap", &results);
187187
}

0 commit comments

Comments
 (0)