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

update ahash and hashbrown #8623

Merged
merged 1 commit into from
May 23, 2023
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
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ impl<T: Asset> Assets<T> {
/// 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<T>) -> Option<&T> {
self.assets.get(&handle.into())
self.assets.get::<HandleId>(&handle.into())
james7132 marked this conversation as resolved.
Show resolved Hide resolved
}

/// Checks if an asset exists for the given handle
pub fn contains(&self, handle: &Handle<T>) -> bool {
self.assets.contains_key(&handle.into())
self.assets.contains_key::<HandleId>(&handle.into())
}

/// Get mutable access to the asset for the given handle.
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_asset/src/path.rs
Original file line number Diff line number Diff line change
@@ -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},
};

Expand Down Expand Up @@ -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()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible those seeds are not very secure. But then they weren't before, so...

}

impl<'a, T> From<T> for AssetPathId
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 11 additions & 9 deletions crates/bevy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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,
Expand All @@ -52,7 +51,7 @@ pub type BoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub type BoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + '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<AHasher>>;

/// A hasher builder that will create a fixed hasher.
#[derive(Debug, Clone, Default)]
Expand All @@ -63,18 +62,21 @@ 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,
Comment on lines -66 to +69
Copy link
Member Author

@mockersf mockersf May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for those seeds, I split the previous two values into the now required four

)
.build_hasher()
}
}

/// A [`HashMap`][hashbrown::HashMap] implementing aHash, a high
/// speed keyed hashing algorithm intended for use in in-memory hashmaps.
///
/// aHash is designed for performance and is NOT cryptographically secure.
pub type HashMap<K, V> = hashbrown::HashMap<K, V, RandomState>;
pub type HashMap<K, V> = hashbrown::HashMap<K, V, BuildHasherDefault<AHasher>>;

/// A stable hash map implementing aHash, a high speed keyed hashing algorithm
/// intended for use in in-memory hashmaps.
Expand All @@ -89,7 +91,7 @@ pub type StableHashMap<K, V> = hashbrown::HashMap<K, V, FixedState>;
/// speed keyed hashing algorithm intended for use in in-memory hashmaps.
///
/// aHash is designed for performance and is NOT cryptographically secure.
pub type HashSet<K> = hashbrown::HashSet<K, RandomState>;
pub type HashSet<K> = hashbrown::HashSet<K, BuildHasherDefault<AHasher>>;

/// A stable hash set implementing aHash, a high speed keyed hashing algorithm
/// intended for use in in-memory hashmaps.
Expand Down
5 changes: 4 additions & 1 deletion examples/3d/tonemapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Tonemapping>(&method)
james7132 marked this conversation as resolved.
Show resolved Hide resolved
.unwrap();
}

#[derive(Resource)]
Expand Down