From 2eef58e7415e3f12e056a413f5884dae5263659d Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 7 Oct 2024 22:56:31 +0100 Subject: [PATCH] refactor: replace ahash with foldhash --- actix-http/Cargo.toml | 2 +- actix-http/src/extensions.rs | 2 +- actix-http/src/header/map.rs | 15 +++++++++++---- actix-web/Cargo.toml | 2 +- actix-web/src/middleware/err_handlers.rs | 4 ++-- actix-web/src/rmap.rs | 8 ++++---- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index f910276f160..d313f5c95ac 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -106,12 +106,12 @@ actix-codec = "0.5" actix-utils = "3" actix-rt = { version = "2.2", default-features = false } -ahash = "0.8" bitflags = "2" bytes = "1" bytestring = "1" derive_more = { version = "1", features = ["as_ref", "deref", "deref_mut", "display", "error", "from"] } encoding_rs = "0.8" +foldhash = "0.1" futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] } http = "0.2.7" httparse = "1.5.1" diff --git a/actix-http/src/extensions.rs b/actix-http/src/extensions.rs index f2047a9ce1d..2ed3973bfb7 100644 --- a/actix-http/src/extensions.rs +++ b/actix-http/src/extensions.rs @@ -31,7 +31,7 @@ impl Hasher for NoOpHasher { /// All entries into this map must be owned types (or static references). #[derive(Default)] pub struct Extensions { - /// Use AHasher with a std HashMap with for faster lookups on the small `TypeId` keys. + // use no-op hasher with a std HashMap with for faster lookups on the small `TypeId` keys map: HashMap, BuildHasherDefault>, } diff --git a/actix-http/src/header/map.rs b/actix-http/src/header/map.rs index 6da01d2c0f4..fddc0737eb4 100644 --- a/actix-http/src/header/map.rs +++ b/actix-http/src/header/map.rs @@ -1,8 +1,12 @@ //! A multi-value [`HeaderMap`] and its iterators. -use std::{borrow::Cow, collections::hash_map, iter, ops}; +use std::{ + borrow::Cow, + collections::{hash_map, HashMap}, + iter, ops, +}; -use ahash::AHashMap; +use foldhash::HashMap as FoldHashMap; use http::header::{HeaderName, HeaderValue}; use smallvec::{smallvec, SmallVec}; @@ -47,7 +51,7 @@ use super::AsHeaderName; /// ``` #[derive(Debug, Clone, Default)] pub struct HeaderMap { - pub(crate) inner: AHashMap, + pub(crate) inner: FoldHashMap, } /// A bespoke non-empty list for HeaderMap values. @@ -116,7 +120,10 @@ impl HeaderMap { /// ``` pub fn with_capacity(capacity: usize) -> Self { HeaderMap { - inner: AHashMap::with_capacity(capacity), + inner: HashMap::with_capacity_and_hasher( + capacity, + foldhash::fast::RandomState::default(), + ), } } diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index f97eab7c947..1d8f801b99c 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -141,13 +141,13 @@ actix-http = { version = "3.7", features = ["ws"] } actix-router = { version = "0.5.3", default-features = false, features = ["http"] } actix-web-codegen = { version = "4.3", optional = true, default-features = false } -ahash = "0.8" bytes = "1" bytestring = "1" cfg-if = "1" cookie = { version = "0.16", features = ["percent-encode"], optional = true } derive_more = { version = "1", features = ["display", "error", "from"] } encoding_rs = "0.8" +foldhash = "0.1" futures-core = { version = "0.3.17", default-features = false } futures-util = { version = "0.3.17", default-features = false } itoa = "1" diff --git a/actix-web/src/middleware/err_handlers.rs b/actix-web/src/middleware/err_handlers.rs index 3c50d5c8f56..649c1a97a6f 100644 --- a/actix-web/src/middleware/err_handlers.rs +++ b/actix-web/src/middleware/err_handlers.rs @@ -8,7 +8,7 @@ use std::{ }; use actix_service::{Service, Transform}; -use ahash::AHashMap; +use foldhash::HashMap as FoldHashMap; use futures_core::{future::LocalBoxFuture, ready}; use pin_project_lite::pin_project; @@ -185,7 +185,7 @@ pub struct ErrorHandlers { handlers: Handlers, } -type Handlers = Rc>>>; +type Handlers = Rc>>>; impl Default for ErrorHandlers { fn default() -> Self { diff --git a/actix-web/src/rmap.rs b/actix-web/src/rmap.rs index 462f3b3132c..b445687ac65 100644 --- a/actix-web/src/rmap.rs +++ b/actix-web/src/rmap.rs @@ -6,7 +6,7 @@ use std::{ }; use actix_router::ResourceDef; -use ahash::AHashMap; +use foldhash::HashMap as FoldHashMap; use url::Url; use crate::{error::UrlGenerationError, request::HttpRequest}; @@ -19,7 +19,7 @@ pub struct ResourceMap { /// Named resources within the tree or, for external resources, it points to isolated nodes /// outside the tree. - named: AHashMap>, + named: FoldHashMap>, parent: RefCell>, @@ -32,7 +32,7 @@ impl ResourceMap { pub fn new(root: ResourceDef) -> Self { ResourceMap { pattern: root, - named: AHashMap::default(), + named: FoldHashMap::default(), parent: RefCell::new(Weak::new()), nodes: Some(Vec::new()), } @@ -86,7 +86,7 @@ impl ResourceMap { } else { let new_node = Rc::new(ResourceMap { pattern: pattern.clone(), - named: AHashMap::default(), + named: FoldHashMap::default(), parent: RefCell::new(Weak::new()), nodes: None, });