diff options
| author | Piotr Czarnecki <pioczarn@gmail.com> | 2014-07-09 18:31:58 +0100 |
|---|---|---|
| committer | Piotr Czarnecki <pioczarn@gmail.com> | 2014-09-02 14:56:43 +0100 |
| commit | 5b0d3adf3debde4cd21e7adb1f434580386d7265 (patch) | |
| tree | 6eab3ff9ce79556333e48c6118de24f06538aceb /src/libstd | |
| parent | dfbd4669cd0ce6298b5cee7d4b5e1585d8228daa (diff) | |
| download | rust-5b0d3adf3debde4cd21e7adb1f434580386d7265.tar.gz rust-5b0d3adf3debde4cd21e7adb1f434580386d7265.zip | |
std: branchless bucket distance for hashmap
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hashmap.rs | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs index 1985128c4e3..d949eeebea0 100644 --- a/src/libstd/collections/hashmap.rs +++ b/src/libstd/collections/hashmap.rs @@ -802,17 +802,9 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { fn bucket_distance(&self, index_of_elem: &table::FullIndex) -> uint { // where the hash of the element that happens to reside at // `index_of_elem` tried to place itself first. - let first_probe_index = self.probe(&index_of_elem.hash(), 0); - let raw_index = index_of_elem.raw_index(); - if first_probe_index <= raw_index { - // probe just went forward - raw_index - first_probe_index - } else { - // probe wrapped around the hashtable - raw_index + (self.table.capacity() - first_probe_index) - } + (raw_index - index_of_elem.hash() as uint) & (self.table.capacity() - 1) } /// Search for a pre-hashed key. |
