Skip to content

Commit be39a7d

Browse files
clarfontheyBD103
authored andcommitted
Update hashbrown to 0.15 (#15801)
Updating dependencies; adopted version of #15696. (Supercedes #15696.) Long answer: hashbrown is no longer using ahash by default, meaning that we can't use the default-hasher methods with ahasher. So, we have to use the longer-winded versions instead. This takes the opportunity to also switch our default hasher as well, but without actually enabling the default-hasher feature for hashbrown, meaning that we'll be able to change our hasher more easily at the cost of all of these method calls being obnoxious forever. One large change from 0.15 is that `insert_unique_unchecked` is now `unsafe`, and for cases where unsafe code was denied at the crate level, I replaced it with `insert`. ## Migration Guide `bevy_utils` has updated its version of `hashbrown` to 0.15 and now defaults to `foldhash` instead of `ahash`. This means that if you've hard-coded your hasher to `bevy_utils::AHasher` or separately used the `ahash` crate in your code, you may need to switch to `foldhash` to ensure that everything works like it does in Bevy.
1 parent 9c470a9 commit be39a7d

File tree

78 files changed

+416
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+416
-350
lines changed

crates/bevy_animation/src/graph.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! The animation graph, which allows animations to be blended together.
22
3-
use core::iter;
4-
use core::ops::{Index, IndexMut, Range};
3+
use core::{
4+
iter,
5+
ops::{Index, IndexMut, Range},
6+
};
57
use std::io::{self, Write};
68

79
use bevy_asset::{
@@ -420,7 +422,7 @@ impl AnimationGraph {
420422
Self {
421423
graph,
422424
root,
423-
mask_groups: HashMap::new(),
425+
mask_groups: HashMap::default(),
424426
}
425427
}
426428

crates/bevy_animation/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ use bevy_reflect::{prelude::ReflectDefault, Reflect, TypePath};
4545
use bevy_time::Time;
4646
use bevy_transform::TransformSystem;
4747
use bevy_utils::{
48-
hashbrown::HashMap,
4948
tracing::{trace, warn},
50-
NoOpHash, PreHashMap, PreHashMapExt, TypeIdMap,
49+
HashMap, NoOpHash, PreHashMap, PreHashMapExt, TypeIdMap,
5150
};
5251
use petgraph::graph::NodeIndex;
5352
use serde::{Deserialize, Serialize};

crates/bevy_app/src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl App {
124124
Self {
125125
sub_apps: SubApps {
126126
main: SubApp::new(),
127-
sub_apps: HashMap::new(),
127+
sub_apps: HashMap::default(),
128128
},
129129
runner: Box::new(run_once),
130130
}

crates/bevy_asset/src/handle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ pub enum UntypedAssetConversionError {
515515
#[cfg(test)]
516516
mod tests {
517517
use bevy_reflect::PartialReflect;
518+
use bevy_utils::FixedHasher;
519+
use core::hash::BuildHasher;
518520

519521
use super::*;
520522

@@ -525,9 +527,7 @@ mod tests {
525527

526528
/// Simple utility to directly hash a value using a fixed hasher
527529
fn hash<T: Hash>(data: &T) -> u64 {
528-
let mut hasher = bevy_utils::AHasher::default();
529-
data.hash(&mut hasher);
530-
hasher.finish()
530+
FixedHasher.hash_one(data)
531531
}
532532

533533
/// Typed and Untyped `Handles` should be equivalent to each other and themselves

crates/bevy_asset/src/id.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,9 @@ mod tests {
418418

419419
/// Simple utility to directly hash a value using a fixed hasher
420420
fn hash<T: Hash>(data: &T) -> u64 {
421-
use core::hash::Hasher;
421+
use core::hash::BuildHasher;
422422

423-
let mut hasher = bevy_utils::AHasher::default();
424-
data.hash(&mut hasher);
425-
hasher.finish()
423+
bevy_utils::FixedHasher.hash_one(data)
426424
}
427425

428426
/// Typed and Untyped `AssetIds` should be equivalent to each other and themselves

crates/bevy_asset/src/io/gated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<R: AssetReader> GatedReader<R> {
4444
/// Creates a new [`GatedReader`], which wraps the given `reader`. Also returns a [`GateOpener`] which
4545
/// can be used to open "path gates" for this [`GatedReader`].
4646
pub fn new(reader: R) -> (Self, GateOpener) {
47-
let gates = Arc::new(RwLock::new(HashMap::new()));
47+
let gates = Arc::new(RwLock::new(HashMap::default()));
4848
(
4949
Self {
5050
reader,

crates/bevy_asset/src/io/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl AssetSourceBuilders {
343343
/// Builds a new [`AssetSources`] collection. If `watch` is true, the unprocessed sources will watch for changes.
344344
/// If `watch_processed` is true, the processed sources will watch for changes.
345345
pub fn build_sources(&mut self, watch: bool, watch_processed: bool) -> AssetSources {
346-
let mut sources = HashMap::new();
346+
let mut sources = <HashMap<_, _>>::default();
347347
for (id, source) in &mut self.sources {
348348
if let Some(data) = source.build(
349349
AssetSourceId::Name(id.clone_owned()),

crates/bevy_asset/src/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub struct LoadedAsset<A: Asset> {
153153
impl<A: Asset> LoadedAsset<A> {
154154
/// Create a new loaded asset. This will use [`VisitAssetDependencies`](crate::VisitAssetDependencies) to populate `dependencies`.
155155
pub fn new_with_dependencies(value: A, meta: Option<Box<dyn AssetMetaDyn>>) -> Self {
156-
let mut dependencies = HashSet::new();
156+
let mut dependencies = <HashSet<_>>::default();
157157
value.visit_dependencies(&mut |id| {
158158
dependencies.insert(id);
159159
});

crates/bevy_asset/src/server/info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ impl AssetInfos {
395395

396396
loaded_asset.value.insert(loaded_asset_id, world);
397397
let mut loading_deps = loaded_asset.dependencies;
398-
let mut failed_deps = HashSet::new();
398+
let mut failed_deps = <HashSet<_>>::default();
399399
let mut dep_error = None;
400400
let mut loading_rec_deps = loading_deps.clone();
401-
let mut failed_rec_deps = HashSet::new();
401+
let mut failed_rec_deps = <HashSet<_>>::default();
402402
let mut rec_dep_error = None;
403403
loading_deps.retain(|dep_id| {
404404
if let Some(dep_info) = self.get_mut(*dep_id) {

crates/bevy_asset/src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ pub fn handle_internal_asset_events(world: &mut World) {
15441544
}
15451545
};
15461546

1547-
let mut paths_to_reload = HashSet::new();
1547+
let mut paths_to_reload = <HashSet<_>>::default();
15481548
let mut handle_event = |source: AssetSourceId<'static>, event: AssetSourceEvent| {
15491549
match event {
15501550
// TODO: if the asset was processed and the processed file was changed, the first modified event

0 commit comments

Comments
 (0)