mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
update ahash and hashbrown (#8623)
# Objective - Update `ahash` and `hashbrown` - Alternative to #5700 and #7420 ## Solution - Update the dependencies This is a breaking change because we were creating two fixed hashers with [`AHasher::new_with_keys`](https://docs.rs/ahash/0.7.6/ahash/struct.AHasher.html#method.new_with_keys), which was a method that existed only for testing purpose and has been removed from public. I replaced it with [`RandomState::with_seeds`](https://docs.rs/ahash/0.8.3/ahash/random_state/struct.RandomState.html#method.with_seeds) which is the proper way to get a fixed hasher (see [this table](https://docs.rs/ahash/0.8.3/ahash/random_state/struct.RandomState.html)). This means that hashes won't be the same across versions --- ## Migration Guide - If you were using hashes to an asset or using one of the fixed hasher exposed by Bevy with a previous version, you will have to update the hashes
This commit is contained in:
parent
c475a2a954
commit
ebac7e8268
5 changed files with 22 additions and 17 deletions
|
@ -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())
|
||||
}
|
||||
|
||||
/// 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.
|
||||
|
|
|
@ -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<T> for AssetPathId
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<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)]
|
||||
|
@ -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<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.
|
||||
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
|
|
Loading…
Reference in a new issue