Skip to content

Commit 28e7631

Browse files
committed
auto merge of #12746 : alexcrichton/rust/issue-12743, r=brson
The arguments were accidentally swapped in the wrong order. Closes #12743
2 parents 5862c0c + 42389b7 commit 28e7631

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/libcollections/hashmap.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,13 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
358358
pub fn with_capacity(capacity: uint) -> HashMap<K, V> {
359359
let mut r = rand::task_rng();
360360
let hasher = SipHasher::new_with_keys(r.gen(), r.gen());
361-
HashMap::with_capacity_and_hasher(hasher, capacity)
361+
HashMap::with_capacity_and_hasher(capacity, hasher)
362362
}
363363
}
364364

365365
impl<K: Hash<S> + Eq, V, S, H: Hasher<S>> HashMap<K, V, H> {
366366
pub fn with_hasher(hasher: H) -> HashMap<K, V, H> {
367-
HashMap::with_capacity_and_hasher(hasher, INITIAL_CAPACITY)
367+
HashMap::with_capacity_and_hasher(INITIAL_CAPACITY, hasher)
368368
}
369369

370370
/// Create an empty HashMap with space for at least `capacity`
@@ -374,7 +374,7 @@ impl<K: Hash<S> + Eq, V, S, H: Hasher<S>> HashMap<K, V, H> {
374374
/// is designed to allow HashMaps to be resistant to attacks that
375375
/// cause many collisions and very poor performance. Setting it
376376
/// manually using this function can expose a DoS attack vector.
377-
pub fn with_capacity_and_hasher(hasher: H, capacity: uint) -> HashMap<K, V, H> {
377+
pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashMap<K, V, H> {
378378
let cap = max(INITIAL_CAPACITY, capacity);
379379
HashMap {
380380
hasher: hasher,
@@ -587,7 +587,8 @@ impl<K: Hash<S> + Eq, V: Eq, S, H: Hasher<S>> Eq for HashMap<K, V, H> {
587587

588588
impl<K: Hash<S> + Eq + Clone, V:Clone, S, H: Hasher<S> + Clone> Clone for HashMap<K, V, H> {
589589
fn clone(&self) -> HashMap<K, V, H> {
590-
let mut new_map = HashMap::with_capacity_and_hasher(self.hasher.clone(), self.len());
590+
let mut new_map = HashMap::with_capacity_and_hasher(self.len(),
591+
self.hasher.clone());
591592
for (key, value) in self.iter() {
592593
new_map.insert((*key).clone(), (*value).clone());
593594
}
@@ -714,7 +715,7 @@ impl<K> Iterator<K> for SetMoveItems<K> {
714715
impl<K: Hash<S> + Eq, V, S, H: Hasher<S> + Default> FromIterator<(K, V)> for HashMap<K, V, H> {
715716
fn from_iterator<T: Iterator<(K, V)>>(iter: &mut T) -> HashMap<K, V, H> {
716717
let (lower, _) = iter.size_hint();
717-
let mut map = HashMap::with_capacity_and_hasher(Default::default(), lower);
718+
let mut map = HashMap::with_capacity_and_hasher(lower, Default::default());
718719
map.extend(iter);
719720
map
720721
}
@@ -730,7 +731,7 @@ impl<K: Hash<S> + Eq, V, S, H: Hasher<S> + Default> Extendable<(K, V)> for HashM
730731

731732
impl<K: Hash<S> + Eq, V, S, H: Hasher<S> + Default> Default for HashMap<K, V, H> {
732733
fn default() -> HashMap<K, V, H> {
733-
HashMap::with_capacity_and_hasher(Default::default(), INITIAL_CAPACITY)
734+
HashMap::with_capacity_and_hasher(INITIAL_CAPACITY, Default::default())
734735
}
735736
}
736737

@@ -802,7 +803,7 @@ impl<T: Hash<SipState> + Eq> HashSet<T, SipHasher> {
802803

803804
impl<T: Hash<S> + Eq, S, H: Hasher<S>> HashSet<T, H> {
804805
pub fn with_hasher(hasher: H) -> HashSet<T, H> {
805-
HashSet::with_capacity_and_hasher(hasher, INITIAL_CAPACITY)
806+
HashSet::with_capacity_and_hasher(INITIAL_CAPACITY, hasher)
806807
}
807808

808809
/// Create an empty HashSet with space for at least `capacity`
@@ -812,9 +813,9 @@ impl<T: Hash<S> + Eq, S, H: Hasher<S>> HashSet<T, H> {
812813
/// are designed to allow HashSets to be resistant to attacks that
813814
/// cause many collisions and very poor performance. Setting them
814815
/// manually using this function can expose a DoS attack vector.
815-
pub fn with_capacity_and_hasher(hasher: H, capacity: uint) -> HashSet<T, H> {
816+
pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashSet<T, H> {
816817
HashSet {
817-
map: HashMap::with_capacity_and_hasher(hasher, capacity)
818+
map: HashMap::with_capacity_and_hasher(capacity, hasher)
818819
}
819820
}
820821

@@ -902,7 +903,7 @@ impl<T: fmt::Show + Hash<S> + Eq, S, H: Hasher<S>> fmt::Show for HashSet<T, H> {
902903
impl<T: Hash<S> + Eq, S, H: Hasher<S> + Default> FromIterator<T> for HashSet<T, H> {
903904
fn from_iterator<Iter: Iterator<T>>(iter: &mut Iter) -> HashSet<T, H> {
904905
let (lower, _) = iter.size_hint();
905-
let mut set = HashSet::with_capacity_and_hasher(Default::default(), lower);
906+
let mut set = HashSet::with_capacity_and_hasher(lower, Default::default());
906907
set.extend(iter);
907908
set
908909
}

src/libserialize/collection_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<
192192
fn decode(d: &mut D) -> HashMap<K, V, H> {
193193
d.read_map(|d, len| {
194194
let hasher = Default::default();
195-
let mut map = HashMap::with_capacity_and_hasher(hasher, len);
195+
let mut map = HashMap::with_capacity_and_hasher(len, hasher);
196196
for i in range(0u, len) {
197197
let key = d.read_map_elt_key(i, |d| Decodable::decode(d));
198198
let val = d.read_map_elt_val(i, |d| Decodable::decode(d));
@@ -228,7 +228,7 @@ impl<
228228
> Decodable<D> for HashSet<T, H> {
229229
fn decode(d: &mut D) -> HashSet<T, H> {
230230
d.read_seq(|d, len| {
231-
let mut set = HashSet::with_capacity_and_hasher(Default::default(), len);
231+
let mut set = HashSet::with_capacity_and_hasher(len, Default::default());
232232
for i in range(0u, len) {
233233
set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
234234
}

0 commit comments

Comments
 (0)