Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace ahash with foldhash #3483

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion actix-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion actix-http/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
}

Expand Down
15 changes: 11 additions & 4 deletions actix-http/src/header/map.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
),
}
}

Expand Down
2 changes: 1 addition & 1 deletion actix-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions actix-web/src/middleware/err_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions actix-web/src/rmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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>>,

Expand All @@ -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()),
}
Expand Down Expand Up @@ -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,
});
Expand Down
Loading