1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-23 16:21:06 +01:00

Switch from fnv to a identity hasher in extensions (#342)

This commit is contained in:
Armin Ronacher 2018-06-22 11:32:32 +02:00 committed by GitHub
parent dda6ee95df
commit 7bc7b4839b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

View File

@ -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"

View File

@ -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<TypeId, Box<Any>, BuildHasherDefault<FnvHasher>>;
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<TypeId, Box<Any>, BuildHasherDefault<IdHasher>>;
/// A type map of request extensions.
pub struct Extensions {

View File

@ -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]