From a21478fd2202a722a0d5dba8acc0491e1f92fae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 17 May 2023 00:57:15 +0200 Subject: [PATCH] update ahash and hashbrown --- crates/bevy_asset/src/assets.rs | 4 ++-- crates/bevy_asset/src/path.rs | 6 +++--- crates/bevy_utils/Cargo.toml | 4 ++-- crates/bevy_utils/src/lib.rs | 20 +++++++++++--------- examples/3d/tonemapping.rs | 5 ++++- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index ac830ef6d262f..74fabdc7c83e5 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -133,12 +133,12 @@ impl Assets { /// This is the main method for accessing asset data from an [Assets] collection. If you need /// mutable access to the asset, use [`get_mut`](Assets::get_mut). pub fn get(&self, handle: &Handle) -> Option<&T> { - self.assets.get(&handle.into()) + self.assets.get::(&handle.into()) } /// Checks if an asset exists for the given handle pub fn contains(&self, handle: &Handle) -> bool { - self.assets.contains_key(&handle.into()) + self.assets.contains_key::(&handle.into()) } /// Get mutable access to the asset for the given handle. diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index 032c8550985b1..f1756dcb6c4fe 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -1,11 +1,11 @@ use bevy_reflect::{ FromReflect, Reflect, ReflectDeserialize, ReflectFromReflect, ReflectSerialize, }; -use bevy_utils::AHasher; +use bevy_utils::{AHasher, RandomState}; use serde::{Deserialize, Serialize}; use std::{ borrow::Cow, - hash::{Hash, Hasher}, + hash::{BuildHasher, Hash, Hasher}, path::{Path, PathBuf}, }; @@ -130,7 +130,7 @@ impl AssetPathId { /// this hasher provides consistent results across runs pub(crate) fn get_hasher() -> AHasher { - AHasher::new_with_keys(42, 23) + RandomState::with_seeds(42, 23, 13, 8).build_hasher() } impl<'a, T> From for AssetPathId diff --git a/crates/bevy_utils/Cargo.toml b/crates/bevy_utils/Cargo.toml index 2407848dd7b89..cc97bb332bda6 100644 --- a/crates/bevy_utils/Cargo.toml +++ b/crates/bevy_utils/Cargo.toml @@ -12,11 +12,11 @@ keywords = ["bevy"] detailed_trace = [] [dependencies] -ahash = "0.7.0" +ahash = "0.8.3" tracing = { version = "0.1", default-features = false, features = ["std"] } instant = { version = "0.1", features = ["wasm-bindgen"] } uuid = { version = "1.1", features = ["v4", "serde"] } -hashbrown = { version = "0.12", features = ["serde"] } +hashbrown = { version = "0.13", features = ["serde"] } bevy_utils_proc_macros = {version = "0.11.0-dev", path = "macros"} petgraph = "0.6" thiserror = "1.0" diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index bac6484d7447e..52e69edbd1a44 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -21,7 +21,7 @@ pub mod syncunsafecell; mod default; mod float_ord; -pub use ahash::AHasher; +pub use ahash::{AHasher, RandomState}; pub use bevy_utils_proc_macros::*; pub use default::default; pub use float_ord::*; @@ -32,12 +32,11 @@ pub use thiserror; pub use tracing; pub use uuid::Uuid; -use ahash::RandomState; use hashbrown::hash_map::RawEntryMut; use std::{ fmt::Debug, future::Future, - hash::{BuildHasher, Hash, Hasher}, + hash::{BuildHasher, BuildHasherDefault, Hash, Hasher}, marker::PhantomData, mem::ManuallyDrop, ops::Deref, @@ -52,7 +51,7 @@ pub type BoxedFuture<'a, T> = Pin + Send + 'a>>; pub type BoxedFuture<'a, T> = Pin + 'a>>; /// A shortcut alias for [`hashbrown::hash_map::Entry`]. -pub type Entry<'a, K, V> = hashbrown::hash_map::Entry<'a, K, V, RandomState>; +pub type Entry<'a, K, V> = hashbrown::hash_map::Entry<'a, K, V, BuildHasherDefault>; /// A hasher builder that will create a fixed hasher. #[derive(Debug, Clone, Default)] @@ -63,10 +62,13 @@ impl std::hash::BuildHasher for FixedState { #[inline] fn build_hasher(&self) -> AHasher { - AHasher::new_with_keys( - 0b1001010111101110000001001100010000000011001001101011001001111000, - 0b1100111101101011011110001011010100000100001111100011010011010101, + RandomState::with_seeds( + 0b10010101111011100000010011000100, + 0b00000011001001101011001001111000, + 0b11001111011010110111100010110101, + 0b00000100001111100011010011010101, ) + .build_hasher() } } @@ -74,7 +76,7 @@ impl std::hash::BuildHasher for FixedState { /// speed keyed hashing algorithm intended for use in in-memory hashmaps. /// /// aHash is designed for performance and is NOT cryptographically secure. -pub type HashMap = hashbrown::HashMap; +pub type HashMap = hashbrown::HashMap>; /// A stable hash map implementing aHash, a high speed keyed hashing algorithm /// intended for use in in-memory hashmaps. @@ -89,7 +91,7 @@ pub type StableHashMap = hashbrown::HashMap; /// speed keyed hashing algorithm intended for use in in-memory hashmaps. /// /// aHash is designed for performance and is NOT cryptographically secure. -pub type HashSet = hashbrown::HashSet; +pub type HashSet = hashbrown::HashSet>; /// A stable hash set implementing aHash, a high speed keyed hashing algorithm /// intended for use in in-memory hashmaps. diff --git a/examples/3d/tonemapping.rs b/examples/3d/tonemapping.rs index 482d2bd1821b5..1d120081d8108 100644 --- a/examples/3d/tonemapping.rs +++ b/examples/3d/tonemapping.rs @@ -400,7 +400,10 @@ fn toggle_tonemapping_method( *method = Tonemapping::BlenderFilmic; } - *color_grading = *per_method_settings.settings.get(&method).unwrap(); + *color_grading = *per_method_settings + .settings + .get::(&method) + .unwrap(); } #[derive(Resource)]