From 7bc7b4839b1ead19d8a2e8937ba78cff9ed307bc Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 22 Jun 2018 11:32:32 +0200 Subject: [PATCH] Switch from fnv to a identity hasher in extensions (#342) --- Cargo.toml | 1 - src/extensions.rs | 30 +++++++++++++++++++++++++++--- src/lib.rs | 1 - 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e60d0793..aa523e17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,6 @@ base64 = "0.9" bitflags = "1.0" failure = "0.1.1" h2 = "0.1" -fnv = "1.0.5" http = "^0.1.5" httparse = "1.2" log = "0.4" diff --git a/src/extensions.rs b/src/extensions.rs index 7fdd142b..02487325 100644 --- a/src/extensions.rs +++ b/src/extensions.rs @@ -1,11 +1,35 @@ use std::any::{Any, TypeId}; use std::collections::HashMap; +use std::hash::{BuildHasherDefault, Hasher}; use std::fmt; -use std::hash::BuildHasherDefault; -use fnv::FnvHasher; +struct IdHasher { + id: u64, +} -type AnyMap = HashMap, BuildHasherDefault>; +impl Default for IdHasher { + fn default() -> IdHasher { + IdHasher { id: 0 } + } +} + +impl Hasher for IdHasher { + fn write(&mut self, bytes: &[u8]) { + for &x in bytes { + self.id.wrapping_add(x as u64); + } + } + + fn write_u64(&mut self, u: u64) { + self.id = u; + } + + fn finish(&self) -> u64 { + self.id + } +} + +type AnyMap = HashMap, BuildHasherDefault>; /// A type map of request extensions. pub struct Extensions { diff --git a/src/lib.rs b/src/lib.rs index 5c7bfbac..22016c11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,7 +97,6 @@ extern crate time; extern crate bitflags; #[macro_use] extern crate failure; -extern crate fnv; #[macro_use] extern crate lazy_static; #[macro_use]