diff --git a/src/map.rs b/src/map.rs index 086abbc514..d0592cb7fa 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1096,8 +1096,12 @@ where K: Borrow, Q: Hash + Eq, { - let hash = make_hash::(&self.hash_builder, k); - self.table.get(hash, equivalent_key(k)) + if self.table.is_empty() { + None + } else { + let hash = make_hash::(&self.hash_builder, k); + self.table.get(hash, equivalent_key(k)) + } } /// Returns the key-value pair corresponding to the supplied key, with a mutable reference to value. @@ -1204,8 +1208,12 @@ where K: Borrow, Q: Hash + Eq, { - let hash = make_hash::(&self.hash_builder, k); - self.table.get_mut(hash, equivalent_key(k)) + if self.table.is_empty() { + None + } else { + let hash = make_hash::(&self.hash_builder, k); + self.table.get_mut(hash, equivalent_key(k)) + } } /// Attempts to get mutable references to `N` values in the map at once.