Skip to content

Commit 41a510d

Browse files
committed
---
yaml --- r: 60863 b: refs/heads/auto c: d01c7d0 h: refs/heads/master i: 60861: 47ea8dd 60859: fafa1c3 60855: f197e08 60847: e894f8f 60831: 6710e59 60799: d98a47f v: v3
1 parent 33be859 commit 41a510d

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: aed53f9bf0eed5526891d3998d2a570840e453f7
17+
refs/heads/auto: d01c7d0d42f204f4532a06b482383a1513ff0e33
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/libstd/hashmap.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ pub fn linear_map_with_capacity<K:Eq + Hash,V>(
7272
fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
7373
k0: u64, k1: u64,
7474
initial_capacity: uint) -> HashMap<K, V> {
75+
let cap = uint::max(INITIAL_CAPACITY, initial_capacity);
7576
HashMap {
7677
k0: k0, k1: k1,
77-
resize_at: resize_at(initial_capacity),
78+
resize_at: resize_at(cap),
7879
size: 0,
79-
buckets: vec::from_fn(initial_capacity, |_| None)
80+
buckets: vec::from_fn(cap, |_| None)
8081
}
8182
}
8283

@@ -480,7 +481,8 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
480481
}
481482

482483
fn consume(&mut self, f: &fn(K, V)) {
483-
let buckets = replace(&mut self.buckets, ~[]);
484+
let buckets = replace(&mut self.buckets,
485+
vec::from_fn(INITIAL_CAPACITY, |_| None));
484486
self.size = 0;
485487

486488
do vec::consume(buckets) |_, bucket| {
@@ -664,6 +666,12 @@ mod test_map {
664666
use super::*;
665667
use uint;
666668

669+
#[test]
670+
fn test_create_capacity_zero() {
671+
let mut m = HashMap::with_capacity(0);
672+
assert!(m.insert(1, 1));
673+
}
674+
667675
#[test]
668676
fn test_insert() {
669677
let mut m = HashMap::new();
@@ -771,6 +779,14 @@ mod test_map {
771779
assert_eq!(m2.get(&2), &3);
772780
}
773781

782+
#[test]
783+
fn test_consume_still_usable() {
784+
let mut m = HashMap::new();
785+
assert!(m.insert(1, 2));
786+
do m.consume |_, _| {}
787+
assert!(m.insert(1, 2));
788+
}
789+
774790
#[test]
775791
fn test_iterate() {
776792
let mut m = linear_map_with_capacity(4);

0 commit comments

Comments
 (0)