about summary refs log tree commit diff
path: root/src/libstd/collections
diff options
context:
space:
mode:
authorAaron Liblong <liblonga@physics.utoronto.ca>2014-12-08 01:03:35 -0500
committerAaron Liblong <liblonga@physics.utoronto.ca>2014-12-19 18:21:24 -0500
commitf6328b60da4c506f0f15dc0194f9b9a89aa61a79 (patch)
treefa079f83c6ba1a4d2651230958c078e7c6ef1a27 /src/libstd/collections
parent99d6956c3bdb290b9fd539c5dc15a2b502da5e7a (diff)
downloadrust-f6328b60da4c506f0f15dc0194f9b9a89aa61a79.tar.gz
rust-f6328b60da4c506f0f15dc0194f9b9a89aa61a79.zip
Reform power_of_two methods for perf increase & semantic change to consider 0 not a power of 2.
Vec panics when attempting to reserve capacity > int::MAX (uint::MAX / 2).
Diffstat (limited to 'src/libstd/collections')
-rw-r--r--src/libstd/collections/hash/map.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index 04dd5afdfa2..6bfea7e3cb2 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -623,10 +623,10 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
     /// Resizes the internal vectors to a new capacity. It's your responsibility to:
     ///   1) Make sure the new capacity is enough for all the elements, accounting
     ///      for the load factor.
-    ///   2) Ensure new_capacity is a power of two.
+    ///   2) Ensure new_capacity is a power of two or zero.
     fn resize(&mut self, new_capacity: uint) {
         assert!(self.table.size() <= new_capacity);
-        assert!(new_capacity.is_power_of_two());
+        assert!(new_capacity.is_power_of_two() || new_capacity == 0);
 
         let mut old_table = replace(&mut self.table, RawTable::new(new_capacity));
         let old_size = old_table.size();