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

[Turbopack] AutoMap, AutoSet and CountHashSet use FxHasher by default #70691

Merged
merged 1 commit into from
Oct 3, 2024
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-auto-hash-map/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ edition = "2021"
workspace = true

[dependencies]
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
smallvec = { workspace = true }
9 changes: 5 additions & 4 deletions turbopack/crates/turbo-tasks-auto-hash-map/src/map.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::{
borrow::Borrow,
collections::{hash_map::RandomState, HashMap},
collections::HashMap,
fmt::{Debug, Formatter},
hash::{BuildHasher, Hash},
hash::{BuildHasher, BuildHasherDefault, Hash},
marker::PhantomData,
};

use rustc_hash::FxHasher;
use serde::{
de::{MapAccess, Visitor},
ser::SerializeMap,
Expand All @@ -16,7 +17,7 @@ use smallvec::SmallVec;
use crate::{MAX_LIST_SIZE, MIN_HASH_SIZE};

#[derive(Clone)]
pub enum AutoMap<K, V, H = RandomState, const I: usize = 0> {
pub enum AutoMap<K, V, H = BuildHasherDefault<FxHasher>, const I: usize = 0> {
List(SmallVec<[(K, V); I]>),
Map(Box<HashMap<K, V, H>>),
}
Expand All @@ -33,7 +34,7 @@ impl<K: Debug, V: Debug, H, const I: usize> Debug for AutoMap<K, V, H, I> {
}
}

impl<K, V> AutoMap<K, V, RandomState, 0> {
impl<K, V> AutoMap<K, V, BuildHasherDefault<FxHasher>, 0> {
/// see [HashMap::new](https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.new)
pub const fn new() -> Self {
AutoMap::List(SmallVec::new_const())
Expand Down
8 changes: 4 additions & 4 deletions turbopack/crates/turbo-tasks-auto-hash-map/src/set.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::{
collections::hash_map::RandomState,
fmt::Debug,
hash::{BuildHasher, Hash},
hash::{BuildHasher, BuildHasherDefault, Hash},
marker::PhantomData,
};

use rustc_hash::FxHasher;
use serde::{Deserialize, Serialize};

use crate::AutoMap;

#[derive(Clone)]
pub struct AutoSet<K, H = RandomState, const I: usize = 0> {
pub struct AutoSet<K, H = BuildHasherDefault<FxHasher>, const I: usize = 0> {
map: AutoMap<K, (), H, I>,
}

Expand All @@ -28,7 +28,7 @@ impl<K: Debug, H, const I: usize> Debug for AutoSet<K, H, I> {
}
}

impl<K> AutoSet<K, RandomState, 0> {
impl<K> AutoSet<K, BuildHasherDefault<FxHasher>, 0> {
/// see [HashSet::new](https://doc.rust-lang.org/std/collections/hash_set/struct.HashSet.html#method.new)
pub const fn new() -> Self {
Self {
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbo-tasks-memory/src/count_hash_set.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{
borrow::Borrow,
collections::hash_map::RandomState,
fmt::{Debug, Formatter},
hash::{BuildHasher, Hash},
hash::{BuildHasher, BuildHasherDefault, Hash},
iter::FilterMap,
};

use auto_hash_map::{
map::{Entry, Iter, RawEntry},
AutoMap,
};
use rustc_hash::FxHasher;

#[derive(Clone)]
pub struct CountHashSet<T, H = RandomState> {
pub struct CountHashSet<T, H = BuildHasherDefault<FxHasher>> {
inner: AutoMap<T, isize, H>,
negative_entries: usize,
}
Expand Down
Loading