]> git.lizzy.rs Git - rust.git/commitdiff
std: branchless bucket distance for hashmap
authorPiotr Czarnecki <pioczarn@gmail.com>
Wed, 9 Jul 2014 17:31:58 +0000 (18:31 +0100)
committerPiotr Czarnecki <pioczarn@gmail.com>
Tue, 2 Sep 2014 13:56:43 +0000 (14:56 +0100)
src/libstd/collections/hashmap.rs

index 1985128c4e307c4017962ce06d88f8be29ce91b0..d949eeebea0da4c08e1382f8f998eb4c5982a0f3 100644 (file)
@@ -802,17 +802,9 @@ fn make_hash<X: Hash<S>>(&self, x: &X) -> table::SafeHash {
     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.