Skip to content

Commit 58736a2

Browse files
committed
perf: Simplify hashing for BloomFilter
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent 77df607 commit 58736a2

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

css-inline/src/html/attributes.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ impl BloomFilter {
2525

2626
#[inline]
2727
fn insert_hash(&mut self, hash: u64) {
28-
self.0 |= 1 << (hash1(hash) % 64);
29-
self.0 |= 1 << (hash2(hash) % 64);
28+
self.0 |= (1u64 << (hash & 63)) | (1u64 << ((hash >> KEY_SIZE) & 63));
3029
}
3130

3231
#[inline]
3332
fn might_contain_hash(self, hash: u64) -> bool {
34-
self.0 & (1 << (hash1(hash) % 64)) != 0 && self.0 & (1 << (hash2(hash) % 64)) != 0
33+
let bits = (1u64 << (hash & 63)) | (1u64 << ((hash >> KEY_SIZE) & 63));
34+
(self.0 & bits) == bits
3535
}
3636

3737
/// Check whether this element MAY have the given class.
@@ -45,17 +45,6 @@ impl BloomFilter {
4545
}
4646

4747
const KEY_SIZE: usize = 32;
48-
const KEY_MASK: u64 = u32::MAX as u64;
49-
50-
#[inline]
51-
fn hash1(hash: u64) -> u64 {
52-
hash & KEY_MASK
53-
}
54-
55-
#[inline]
56-
fn hash2(hash: u64) -> u64 {
57-
(hash >> KEY_SIZE) & KEY_MASK
58-
}
5948

6049
#[derive(Debug)]
6150
pub(crate) enum Cache {

0 commit comments

Comments
 (0)