From b45c6cd66b5fcb37a7b4b3afcd4cb35cc25f2d9b Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 4 Dec 2019 18:32:18 +0600 Subject: [PATCH] replace hashbrown with std hashmap --- Cargo.toml | 2 +- actix-http/Cargo.toml | 2 +- actix-http/src/client/pool.rs | 6 +++--- actix-http/src/extensions.rs | 6 +++--- actix-http/src/header/map.rs | 11 ++++++----- actix-session/Cargo.toml | 1 - actix-session/src/lib.rs | 2 +- awc/Cargo.toml | 1 - src/middleware/errhandlers.rs | 8 ++++---- src/rmap.rs | 6 +++--- 10 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4093ca3b..d5b16844 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,7 +87,7 @@ bytes = "0.4" derive_more = "0.99.2" encoding_rs = "0.8" futures = "0.3.1" -hashbrown = "0.6.3" +fxhash = "0.2.1" log = "0.4" mime = "0.3" net2 = "0.2.33" diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 54e83fbc..d81c4611 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -64,7 +64,7 @@ derive_more = "0.99.2" either = "1.5.2" encoding_rs = "0.8" futures = "0.3.1" -hashbrown = "0.6.3" +fxhash = "0.2.1" h2 = "0.2.0-alpha.3" http = "0.1.17" httparse = "1.3" diff --git a/actix-http/src/client/pool.rs b/actix-http/src/client/pool.rs index c6103986..938ccb5d 100644 --- a/actix-http/src/client/pool.rs +++ b/actix-http/src/client/pool.rs @@ -12,8 +12,8 @@ use actix_service::Service; use actix_utils::{oneshot, task::LocalWaker}; use bytes::Bytes; use futures::future::{poll_fn, FutureExt, LocalBoxFuture}; +use fxhash::FxHashMap; use h2::client::{handshake, Connection, SendRequest}; -use hashbrown::HashMap; use http::uri::Authority; use indexmap::IndexSet; use slab::Slab; @@ -66,7 +66,7 @@ where acquired: 0, waiters: Slab::new(), waiters_queue: IndexSet::new(), - available: HashMap::new(), + available: FxHashMap::default(), waker: LocalWaker::new(), })), ) @@ -259,7 +259,7 @@ pub(crate) struct Inner { disconnect_timeout: Option, limit: usize, acquired: usize, - available: HashMap>>, + available: FxHashMap>>, waiters: Slab< Option<( Connect, diff --git a/actix-http/src/extensions.rs b/actix-http/src/extensions.rs index c6266f56..066e0a3c 100644 --- a/actix-http/src/extensions.rs +++ b/actix-http/src/extensions.rs @@ -1,12 +1,12 @@ use std::any::{Any, TypeId}; use std::fmt; -use hashbrown::HashMap; +use fxhash::FxHashMap; #[derive(Default)] /// A type map of request extensions. pub struct Extensions { - map: HashMap>, + map: FxHashMap>, } impl Extensions { @@ -14,7 +14,7 @@ impl Extensions { #[inline] pub fn new() -> Extensions { Extensions { - map: HashMap::default(), + map: FxHashMap::default(), } } diff --git a/actix-http/src/header/map.rs b/actix-http/src/header/map.rs index f2f1ba51..5fcf79f7 100644 --- a/actix-http/src/header/map.rs +++ b/actix-http/src/header/map.rs @@ -1,6 +1,7 @@ +use std::collections::hash_map::{self, Entry}; + use either::Either; -use hashbrown::hash_map::{self, Entry}; -use hashbrown::HashMap; +use fxhash::FxHashMap; use http::header::{HeaderName, HeaderValue}; use http::HttpTryFrom; @@ -11,7 +12,7 @@ use http::HttpTryFrom; /// [`HeaderName`]: struct.HeaderName.html #[derive(Debug, Clone)] pub struct HeaderMap { - pub(crate) inner: HashMap, + pub(crate) inner: FxHashMap, } #[derive(Debug, Clone)] @@ -56,7 +57,7 @@ impl HeaderMap { /// allocate. pub fn new() -> Self { HeaderMap { - inner: HashMap::new(), + inner: FxHashMap::default(), } } @@ -70,7 +71,7 @@ impl HeaderMap { /// More capacity than requested may be allocated. pub fn with_capacity(capacity: usize) -> HeaderMap { HeaderMap { - inner: HashMap::with_capacity(capacity), + inner: FxHashMap::with_capacity_and_hasher(capacity, Default::default()), } } diff --git a/actix-session/Cargo.toml b/actix-session/Cargo.toml index 96c88251..d396a787 100644 --- a/actix-session/Cargo.toml +++ b/actix-session/Cargo.toml @@ -29,7 +29,6 @@ actix-service = "1.0.0-alpha.2" bytes = "0.4" derive_more = "0.99.2" futures = "0.3.1" -hashbrown = "0.6.3" serde = "1.0" serde_json = "1.0" time = "0.1.42" diff --git a/actix-session/src/lib.rs b/actix-session/src/lib.rs index def35a1e..6f23ef91 100644 --- a/actix-session/src/lib.rs +++ b/actix-session/src/lib.rs @@ -43,12 +43,12 @@ //! } //! ``` use std::cell::RefCell; +use std::collections::HashMap; use std::rc::Rc; use actix_web::dev::{Extensions, Payload, ServiceRequest, ServiceResponse}; use actix_web::{Error, FromRequest, HttpMessage, HttpRequest}; use futures::future::{ok, Ready}; -use hashbrown::HashMap; use serde::de::DeserializeOwned; use serde::Serialize; use serde_json; diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 7c181690..e884aadd 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -72,5 +72,4 @@ actix-server = { version = "1.0.0-alpha.2" } brotli2 = { version="0.3.2" } flate2 = { version="1.0.2" } env_logger = "0.6" -rand = "0.7" webpki = { version = "0.21" } diff --git a/src/middleware/errhandlers.rs b/src/middleware/errhandlers.rs index 3dc1f082..7a868493 100644 --- a/src/middleware/errhandlers.rs +++ b/src/middleware/errhandlers.rs @@ -4,7 +4,7 @@ use std::task::{Context, Poll}; use actix_service::{Service, Transform}; use futures::future::{ok, FutureExt, LocalBoxFuture, Ready}; -use hashbrown::HashMap; +use fxhash::FxHashMap; use crate::dev::{ServiceRequest, ServiceResponse}; use crate::error::{Error, Result}; @@ -52,13 +52,13 @@ type ErrorHandler = dyn Fn(ServiceResponse) -> Result { - handlers: Rc>>>, + handlers: Rc>>>, } impl Default for ErrorHandlers { fn default() -> Self { ErrorHandlers { - handlers: Rc::new(HashMap::new()), + handlers: Rc::new(FxHashMap::default()), } } } @@ -105,7 +105,7 @@ where #[doc(hidden)] pub struct ErrorHandlersMiddleware { service: S, - handlers: Rc>>>, + handlers: Rc>>>, } impl Service for ErrorHandlersMiddleware diff --git a/src/rmap.rs b/src/rmap.rs index 42ddb134..47092608 100644 --- a/src/rmap.rs +++ b/src/rmap.rs @@ -2,7 +2,7 @@ use std::cell::RefCell; use std::rc::Rc; use actix_router::ResourceDef; -use hashbrown::HashMap; +use fxhash::FxHashMap; use url::Url; use crate::error::UrlGenerationError; @@ -12,7 +12,7 @@ use crate::request::HttpRequest; pub struct ResourceMap { root: ResourceDef, parent: RefCell>>, - named: HashMap, + named: FxHashMap, patterns: Vec<(ResourceDef, Option>)>, } @@ -21,7 +21,7 @@ impl ResourceMap { ResourceMap { root, parent: RefCell::new(None), - named: HashMap::new(), + named: FxHashMap::default(), patterns: Vec::new(), } }