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

refactor: replace ahash with foldhash

This commit is contained in:
Rob Ede 2024-10-07 22:56:31 +01:00
parent 049b49290d
commit 2eef58e741
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
6 changed files with 20 additions and 13 deletions

View File

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

View File

@ -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<TypeId, Box<dyn Any>, BuildHasherDefault<NoOpHasher>>,
}

View File

@ -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<HeaderName, Value>,
pub(crate) inner: FoldHashMap<HeaderName, Value>,
}
/// 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(),
),
}
}

View File

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

View File

@ -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<B> {
handlers: Handlers<B>,
}
type Handlers<B> = Rc<AHashMap<StatusCode, Box<ErrorHandler<B>>>>;
type Handlers<B> = Rc<FoldHashMap<StatusCode, Box<ErrorHandler<B>>>>;
impl<B> Default for ErrorHandlers<B> {
fn default() -> Self {

View File

@ -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<String, Rc<ResourceMap>>,
named: FoldHashMap<String, Rc<ResourceMap>>,
parent: RefCell<Weak<ResourceMap>>,
@ -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,
});