Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ std = []

[dependencies]
bytes = "1"
fnv = "1.0.5"
itoa = "1"

[dev-dependencies]
Expand Down
30 changes: 27 additions & 3 deletions src/header/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3654,8 +3654,6 @@ fn hash_elem_using<K>(danger: &Danger, k: &K) -> HashValue
where
K: Hash + ?Sized,
{
use fnv::FnvHasher;

const MASK: u64 = (MAX_SIZE as u64) - 1;

let hash = match *danger {
Expand All @@ -3667,7 +3665,7 @@ where
}
// Fast hash
_ => {
let mut h = FnvHasher::default();
let mut h = FnvHasher::new();
k.hash(&mut h);
h.finish()
}
Expand All @@ -3676,6 +3674,32 @@ where
HashValue((hash & MASK) as u16)
}

struct FnvHasher(u64);

impl FnvHasher {
#[inline]
fn new() -> Self {
FnvHasher(0xcbf29ce484222325)
}
}

impl std::hash::Hasher for FnvHasher {
#[inline]
fn finish(&self) -> u64 {
self.0
}

#[inline]
fn write(&mut self, bytes: &[u8]) {
let mut hash = self.0;
for &b in bytes {
hash = hash ^ (b as u64);
hash = hash.wrapping_mul(0x100000001b3);
}
self.0 = hash;
}
}

/*
*
* ===== impl IntoHeaderName / AsHeaderName =====
Expand Down