diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 50a00714ea06c..ef40c0706b4e2 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -966,7 +966,7 @@ impl, V, S, H: Hasher> HashMap { pub fn clear(&mut self) { // Prevent reallocations from happening from now on. Makes it possible // for the map to be reused but has a downside: reserves permanently. - self.resize_policy.reserve(self.table.size()); + self.resize_policy.reserve(max(self.table.size(), INITIAL_CAPACITY).next_power_of_two()); let cap = self.table.capacity(); let mut buckets = Bucket::first(&mut self.table);