From cf982d17b9ef0966c77d1161ed1346dde543136e Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Sat, 10 Jun 2017 09:47:15 -0700 Subject: [PATCH] Shift by KEY_SIZE instead of something larger. Currently all Gecko and Servo do the KEY_SHIFT thing, but there's no reason we need to follow that here. See https://bugzilla.mozilla.org/show_bug.cgi?id=1371949#c10 MozReview-Commit-ID: CqNi7r9e5s0 --- components/selectors/bloom.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/selectors/bloom.rs b/components/selectors/bloom.rs index b60fc1be0b8..0f6fabbaa10 100644 --- a/components/selectors/bloom.rs +++ b/components/selectors/bloom.rs @@ -7,10 +7,13 @@ use fnv::FnvHasher; use std::hash::{Hash, Hasher}; +// The top 12 bits of the 32-bit hash value are not used by the bloom filter. +// Consumers may rely on this to pack hashes more efficiently. +pub const BLOOM_HASH_MASK: u32 = 0x00ffffff; const KEY_SIZE: usize = 12; + const ARRAY_SIZE: usize = 1 << KEY_SIZE; const KEY_MASK: u32 = (1 << KEY_SIZE) - 1; -const KEY_SHIFT: usize = 16; /// A counting Bloom filter with 8-bit counters. For now we assume /// that having two hash functions is enough, but we may revisit that @@ -183,7 +186,7 @@ fn hash1(hash: u32) -> u32 { #[inline] fn hash2(hash: u32) -> u32 { - (hash >> KEY_SHIFT) & KEY_MASK + (hash >> KEY_SIZE) & KEY_MASK } #[test]