bevy_utils: Add BuildHasher parameter to bevy_utils::Entry type alias (#12308)

# Objective

`bevy_utils::Entry` is only useful when using
`BuildHasherDefault<AHasher>`. It would be great if we didn't have to
write out `bevy_utils::hashbrown::hash_map::Entry` whenever we want to
use a different `BuildHasher`, such as when working with
`bevy_utils::TypeIdMap`.

## Solution

Give `bevy_utils::Entry` a new optional type parameter for defining a
custom `BuildHasher`, such as `NoOpHash`. This parameter defaults to
`BuildHasherDefault<AHasher>`— the `BuildHasher` used by
`bevy_utils::HashMap`.

---

## Changelog

- Added an optional third type parameter to `bevy_utils::Entry` to
specify a custom `BuildHasher`
This commit is contained in:
Gino Valente 2024-03-04 19:45:05 -07:00 committed by GitHub
parent 921ba54acf
commit 5b69613e42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 5 deletions

View file

@ -205,7 +205,7 @@ impl AssetInfos {
.ok_or(GetOrCreateHandleInternalError::HandleMissingButTypeIdNotSpecified)?; .ok_or(GetOrCreateHandleInternalError::HandleMissingButTypeIdNotSpecified)?;
match handles.entry(type_id) { match handles.entry(type_id) {
bevy_utils::hashbrown::hash_map::Entry::Occupied(entry) => { Entry::Occupied(entry) => {
let id = *entry.get(); let id = *entry.get();
// if there is a path_to_id entry, info always exists // if there is a path_to_id entry, info always exists
let info = self.infos.get_mut(&id).unwrap(); let info = self.infos.get_mut(&id).unwrap();
@ -246,7 +246,7 @@ impl AssetInfos {
} }
} }
// The entry does not exist, so this is a "fresh" asset load. We must create a new handle // The entry does not exist, so this is a "fresh" asset load. We must create a new handle
bevy_utils::hashbrown::hash_map::Entry::Vacant(entry) => { Entry::Vacant(entry) => {
let should_load = match loading_mode { let should_load = match loading_mode {
HandleLoadingMode::NotLoading => false, HandleLoadingMode::NotLoading => false,
HandleLoadingMode::Request | HandleLoadingMode::Force => true, HandleLoadingMode::Request | HandleLoadingMode::Force => true,

View file

@ -202,8 +202,8 @@ impl TypeRegistry {
get_registration: impl FnOnce() -> TypeRegistration, get_registration: impl FnOnce() -> TypeRegistration,
) -> bool { ) -> bool {
match self.registrations.entry(type_id) { match self.registrations.entry(type_id) {
bevy_utils::hashbrown::hash_map::Entry::Occupied(_) => false, bevy_utils::Entry::Occupied(_) => false,
bevy_utils::hashbrown::hash_map::Entry::Vacant(entry) => { bevy_utils::Entry::Vacant(entry) => {
let registration = get_registration(); let registration = get_registration();
Self::update_registration_indices( Self::update_registration_indices(
&registration, &registration,

View file

@ -64,7 +64,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>>; pub type BoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
/// A shortcut alias for [`hashbrown::hash_map::Entry`]. /// A shortcut alias for [`hashbrown::hash_map::Entry`].
pub type Entry<'a, K, V> = hashbrown::hash_map::Entry<'a, K, V, BuildHasherDefault<AHasher>>; pub type Entry<'a, K, V, S = BuildHasherDefault<AHasher>> = hashbrown::hash_map::Entry<'a, K, V, S>;
/// A hasher builder that will create a fixed hasher. /// A hasher builder that will create a fixed hasher.
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]