Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,12 @@ where
K: Borrow<Q>,
Q: Hash + Eq,
{
let hash = make_hash::<K, Q, S>(&self.hash_builder, k);
self.table.get(hash, equivalent_key(k))
if self.table.is_empty() {
None
} else {
let hash = make_hash::<K, Q, S>(&self.hash_builder, k);
self.table.get(hash, equivalent_key(k))
}
Comment on lines +1099 to +1104
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may make sense, if the map contains a single element and the table is small, to skip hashing and compare directly the key with the key of the single entry in the table

}

/// Returns the key-value pair corresponding to the supplied key, with a mutable reference to value.
Expand Down Expand Up @@ -1204,8 +1208,12 @@ where
K: Borrow<Q>,
Q: Hash + Eq,
{
let hash = make_hash::<K, Q, S>(&self.hash_builder, k);
self.table.get_mut(hash, equivalent_key(k))
if self.table.is_empty() {
None
} else {
let hash = make_hash::<K, Q, S>(&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.
Expand Down