From 1f86e6e08f1cf54d46250a6c7b16f1ef91531404 Mon Sep 17 00:00:00 2001 From: Lorenzo Giannini <155078354+LoweredgamesDev@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:13:27 +0200 Subject: [PATCH] Update hashbrown to 0.15 --- crates/bevy_animation/src/graph.rs | 2 +- crates/bevy_app/src/app.rs | 2 +- crates/bevy_asset/src/io/gated.rs | 2 +- crates/bevy_asset/src/io/source.rs | 2 +- crates/bevy_asset/src/loader.rs | 2 +- crates/bevy_asset/src/server/info.rs | 4 +- crates/bevy_asset/src/server/mod.rs | 2 +- .../bevy_core_pipeline/src/upscaling/mod.rs | 2 +- .../src/ui_debug_overlay/inset.rs | 2 +- crates/bevy_ecs/src/archetype.rs | 4 +- crates/bevy_ecs/src/bundle.rs | 9 +- crates/bevy_ecs/src/entity/visit_entities.rs | 2 +- crates/bevy_ecs/src/lib.rs | 90 +++++++++++++------ crates/bevy_ecs/src/schedule/graph_utils.rs | 14 +-- crates/bevy_ecs/src/schedule/schedule.rs | 18 ++-- crates/bevy_ecs/src/world/entity_ref.rs | 4 +- crates/bevy_ecs/src/world/mod.rs | 28 +++--- crates/bevy_gltf/src/loader.rs | 12 +-- crates/bevy_mesh/src/primitives/dim2.rs | 2 +- crates/bevy_pbr/src/light_probe/mod.rs | 2 +- crates/bevy_pbr/src/meshlet/from_mesh.rs | 4 +- .../bevy_pbr/src/meshlet/instance_manager.rs | 4 +- .../src/meshlet/meshlet_mesh_manager.rs | 2 +- crates/bevy_pbr/src/render/mesh.rs | 2 +- crates/bevy_picking/src/focus.rs | 2 +- crates/bevy_reflect/Cargo.toml | 2 +- crates/bevy_reflect/src/impls/std.rs | 8 +- crates/bevy_reflect/src/kind.rs | 2 +- crates/bevy_reflect/src/lib.rs | 12 ++- crates/bevy_reflect/src/map.rs | 2 +- crates/bevy_reflect/src/serde/de/mod.rs | 4 +- crates/bevy_reflect/src/serde/ser/mod.rs | 4 +- crates/bevy_reflect/src/set.rs | 2 +- crates/bevy_remote/src/builtin_methods.rs | 4 +- crates/bevy_remote/src/http.rs | 2 +- crates/bevy_render/src/camera/camera.rs | 10 ++- .../src/camera/camera_driver_node.rs | 2 +- crates/bevy_render/src/mesh/allocator.rs | 14 +-- crates/bevy_render/src/render_asset.rs | 2 +- .../src/render_resource/pipeline_cache.rs | 4 +- .../render_resource/pipeline_specializer.rs | 13 ++- crates/bevy_scene/src/scene_filter.rs | 10 +-- crates/bevy_scene/src/scene_spawner.rs | 2 +- crates/bevy_scene/src/serde.rs | 2 +- crates/bevy_ui/src/stack.rs | 2 +- crates/bevy_ui/src/update.rs | 2 +- crates/bevy_utils/Cargo.toml | 2 +- crates/bevy_utils/src/lib.rs | 4 +- examples/3d/tonemapping.rs | 2 +- examples/animation/animation_masks.rs | 2 +- examples/ecs/dynamic.rs | 3 +- examples/games/contributors.rs | 2 +- examples/reflection/dynamic_types.rs | 4 +- tests/ecs/ambiguity_detection.rs | 2 +- tools/build-templated-pages/Cargo.toml | 2 +- 55 files changed, 205 insertions(+), 142 deletions(-) diff --git a/crates/bevy_animation/src/graph.rs b/crates/bevy_animation/src/graph.rs index 45144aa4cd1cd5..054ce3b529b965 100644 --- a/crates/bevy_animation/src/graph.rs +++ b/crates/bevy_animation/src/graph.rs @@ -406,7 +406,7 @@ impl AnimationGraph { Self { graph, root, - mask_groups: HashMap::new(), + mask_groups: HashMap::default(), } } diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 7050c61d5888af..688014ace84fd4 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -124,7 +124,7 @@ impl App { Self { sub_apps: SubApps { main: SubApp::new(), - sub_apps: HashMap::new(), + sub_apps: HashMap::default(), }, runner: Box::new(run_once), } diff --git a/crates/bevy_asset/src/io/gated.rs b/crates/bevy_asset/src/io/gated.rs index cb205f12a81bd8..388145a4686b05 100644 --- a/crates/bevy_asset/src/io/gated.rs +++ b/crates/bevy_asset/src/io/gated.rs @@ -44,7 +44,7 @@ impl GatedReader { /// Creates a new [`GatedReader`], which wraps the given `reader`. Also returns a [`GateOpener`] which /// can be used to open "path gates" for this [`GatedReader`]. pub fn new(reader: R) -> (Self, GateOpener) { - let gates = Arc::new(RwLock::new(HashMap::new())); + let gates = Arc::new(RwLock::new(HashMap::default())); ( Self { reader, diff --git a/crates/bevy_asset/src/io/source.rs b/crates/bevy_asset/src/io/source.rs index c1185a64957c9d..5fb5591edcf8bc 100644 --- a/crates/bevy_asset/src/io/source.rs +++ b/crates/bevy_asset/src/io/source.rs @@ -343,7 +343,7 @@ impl AssetSourceBuilders { /// Builds a new [`AssetSources`] collection. If `watch` is true, the unprocessed sources will watch for changes. /// If `watch_processed` is true, the processed sources will watch for changes. pub fn build_sources(&mut self, watch: bool, watch_processed: bool) -> AssetSources { - let mut sources = HashMap::new(); + let mut sources = HashMap::default(); for (id, source) in &mut self.sources { if let Some(data) = source.build( AssetSourceId::Name(id.clone_owned()), diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index 7192fe265ca443..e4c0a3383c9e10 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -153,7 +153,7 @@ pub struct LoadedAsset { impl LoadedAsset { /// Create a new loaded asset. This will use [`VisitAssetDependencies`](crate::VisitAssetDependencies) to populate `dependencies`. pub fn new_with_dependencies(value: A, meta: Option>) -> Self { - let mut dependencies = HashSet::new(); + let mut dependencies = HashSet::default(); value.visit_dependencies(&mut |id| { dependencies.insert(id); }); diff --git a/crates/bevy_asset/src/server/info.rs b/crates/bevy_asset/src/server/info.rs index 5fd0193c779ecc..31c677eeee8110 100644 --- a/crates/bevy_asset/src/server/info.rs +++ b/crates/bevy_asset/src/server/info.rs @@ -392,10 +392,10 @@ impl AssetInfos { loaded_asset.value.insert(loaded_asset_id, world); let mut loading_deps = loaded_asset.dependencies; - let mut failed_deps = HashSet::new(); + let mut failed_deps = HashSet::default(); let mut dep_error = None; let mut loading_rec_deps = loading_deps.clone(); - let mut failed_rec_deps = HashSet::new(); + let mut failed_rec_deps = HashSet::default(); let mut rec_dep_error = None; loading_deps.retain(|dep_id| { if let Some(dep_info) = self.get_mut(*dep_id) { diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index acf351843dfc6a..86a6bb2cbf8a50 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -1414,7 +1414,7 @@ pub fn handle_internal_asset_events(world: &mut World) { } }; - let mut paths_to_reload = HashSet::new(); + let mut paths_to_reload = HashSet::default(); let mut handle_event = |source: AssetSourceId<'static>, event: AssetSourceEvent| { match event { // TODO: if the asset was processed and the processed file was changed, the first modified event diff --git a/crates/bevy_core_pipeline/src/upscaling/mod.rs b/crates/bevy_core_pipeline/src/upscaling/mod.rs index 42f6744bfb32c5..c415c42aceaef7 100644 --- a/crates/bevy_core_pipeline/src/upscaling/mod.rs +++ b/crates/bevy_core_pipeline/src/upscaling/mod.rs @@ -43,7 +43,7 @@ fn prepare_view_upscaling_pipelines( blit_pipeline: Res, view_targets: Query<(Entity, &ViewTarget, Option<&ExtractedCamera>)>, ) { - let mut output_textures = HashSet::new(); + let mut output_textures = HashSet::default(); for (entity, view_target, camera) in view_targets.iter() { let out_texture_id = view_target.out_texture().id(); let blend_state = if let Some(ExtractedCamera { diff --git a/crates/bevy_dev_tools/src/ui_debug_overlay/inset.rs b/crates/bevy_dev_tools/src/ui_debug_overlay/inset.rs index 92522f6fbe68f8..1a9daa925bc334 100644 --- a/crates/bevy_dev_tools/src/ui_debug_overlay/inset.rs +++ b/crates/bevy_dev_tools/src/ui_debug_overlay/inset.rs @@ -52,7 +52,7 @@ struct DrawnLines { impl DrawnLines { fn new(width: f32) -> Self { DrawnLines { - lines: HashMap::new(), + lines: HashMap::default(), width, } } diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index 3f5456370258cd..23da6d6e2fb168 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -402,7 +402,7 @@ impl Archetype { // component in the `table_components` vector component_index .entry(component_id) - .or_insert_with(HashMap::new) + .or_default() .insert(id, ArchetypeRecord { column: Some(idx) }); } @@ -420,7 +420,7 @@ impl Archetype { ); component_index .entry(component_id) - .or_insert_with(HashMap::new) + .or_default() .insert(id, ArchetypeRecord { column: None }); } Self { diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index 8dacc98a911d7d..fac887c87b40eb 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -380,7 +380,7 @@ impl BundleInfo { if deduped.len() != component_ids.len() { // TODO: Replace with `Vec::partition_dedup` once https://github.com/rust-lang/rust/issues/54279 is stabilized - let mut seen = HashSet::new(); + let mut seen = HashSet::default(); let mut dups = Vec::new(); for id in component_ids { if !seen.insert(id) { @@ -1422,8 +1422,11 @@ impl Bundles { .or_insert_with(|| { let (id, storages) = initialize_dynamic_bundle(bundle_infos, components, Vec::from(component_ids)); - self.dynamic_bundle_storages - .insert_unique_unchecked(id, storages); + // SAFETY: We know the ID is unique + unsafe { + self.dynamic_bundle_storages + .insert_unique_unchecked(id, storages); + } (component_ids.into(), id) }); *bundle_id diff --git a/crates/bevy_ecs/src/entity/visit_entities.rs b/crates/bevy_ecs/src/entity/visit_entities.rs index 79b5197d2ea79b..abce76853d403f 100644 --- a/crates/bevy_ecs/src/entity/visit_entities.rs +++ b/crates/bevy_ecs/src/entity/visit_entities.rs @@ -113,7 +113,7 @@ mod tests { let mut entity_map = EntityHashMap::::default(); let mut remapped = Foo { ordered: vec![], - unordered: HashSet::new(), + unordered: HashSet::default(), single: Entity::PLACEHOLDER, not_an_entity: foo.not_an_entity.clone(), }; diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 3a15cabe3f529b..618ad1396f16f9 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -417,7 +417,7 @@ mod tests { let mut world = World::new(); let e = world.spawn((TableStored("abc"), A(123))).id(); let f = world.spawn((TableStored("def"), A(456), B(1))).id(); - let mut results = HashSet::new(); + let mut results = HashSet::default(); world .query::<(Entity, &A)>() .iter(&world) @@ -594,7 +594,9 @@ mod tests { .collect::>(); assert_eq!( ents, - HashSet::from([(e, None, A(123)), (f, Some(SparseStored(1)), A(456))]) + ([(e, None, A(123)), (f, Some(SparseStored(1)), A(456))]) + .into_iter() + .collect::>() ); } @@ -626,7 +628,9 @@ mod tests { .iter(&world) .map(|(e, &i, &b)| (e, i, b)) .collect::>(), - HashSet::from([(e1, A(1), B(3)), (e2, A(2), B(4))]) + ([(e1, A(1), B(3)), (e2, A(2), B(4))]) + .into_iter() + .collect::>() ); assert_eq!(world.entity_mut(e1).take::(), Some(A(1))); assert_eq!( @@ -643,7 +647,9 @@ mod tests { .iter(&world) .map(|(e, &B(b), &TableStored(s))| (e, b, s)) .collect::>(), - HashSet::from([(e2, 4, "xyz"), (e1, 3, "abc")]) + ([(e2, 4, "xyz"), (e1, 3, "abc")]) + .into_iter() + .collect::>() ); world.entity_mut(e1).insert(A(43)); assert_eq!( @@ -652,7 +658,9 @@ mod tests { .iter(&world) .map(|(e, &i, &b)| (e, i, b)) .collect::>(), - HashSet::from([(e2, A(2), B(4)), (e1, A(43), B(3))]) + ([(e2, A(2), B(4)), (e1, A(43), B(3))]) + .into_iter() + .collect::>() ); world.entity_mut(e1).insert(C); assert_eq!( @@ -950,7 +958,7 @@ mod tests { assert_eq!( get_filtered::>(&mut world), - HashSet::from([e1, e3]) + ([e1, e3]).into_iter().collect::>() ); // ensure changing an entity's archetypes also moves its changed state @@ -958,7 +966,7 @@ mod tests { assert_eq!( get_filtered::>(&mut world), - HashSet::from([e3, e1]), + ([e3, e1]).into_iter().collect::>(), "changed entities list should not change" ); @@ -967,7 +975,7 @@ mod tests { assert_eq!( get_filtered::>(&mut world), - HashSet::from([e3, e1]), + ([e3, e1]).into_iter().collect::>(), "changed entities list should not change" ); @@ -975,7 +983,7 @@ mod tests { assert!(world.despawn(e2)); assert_eq!( get_filtered::>(&mut world), - HashSet::from([e3, e1]), + ([e3, e1]).into_iter().collect::>(), "changed entities list should not change" ); @@ -983,7 +991,7 @@ mod tests { assert!(world.despawn(e1)); assert_eq!( get_filtered::>(&mut world), - HashSet::from([e3]), + ([e3]).into_iter().collect::>(), "e1 should no longer be returned" ); @@ -994,11 +1002,20 @@ mod tests { let e4 = world.spawn_empty().id(); world.entity_mut(e4).insert(A(0)); - assert_eq!(get_filtered::>(&mut world), HashSet::from([e4])); - assert_eq!(get_filtered::>(&mut world), HashSet::from([e4])); + assert_eq!( + get_filtered::>(&mut world), + ([e4]).into_iter().collect::>() + ); + assert_eq!( + get_filtered::>(&mut world), + ([e4]).into_iter().collect::>() + ); world.entity_mut(e4).insert(A(1)); - assert_eq!(get_filtered::>(&mut world), HashSet::from([e4])); + assert_eq!( + get_filtered::>(&mut world), + ([e4]).into_iter().collect::>() + ); world.clear_trackers(); @@ -1007,9 +1024,18 @@ mod tests { world.entity_mut(e4).insert((A(0), B(0))); assert!(get_filtered::>(&mut world).is_empty()); - assert_eq!(get_filtered::>(&mut world), HashSet::from([e4])); - assert_eq!(get_filtered::>(&mut world), HashSet::from([e4])); - assert_eq!(get_filtered::>(&mut world), HashSet::from([e4])); + assert_eq!( + get_filtered::>(&mut world), + ([e4]).into_iter().collect::>() + ); + assert_eq!( + get_filtered::>(&mut world), + ([e4]).into_iter().collect::>() + ); + assert_eq!( + get_filtered::>(&mut world), + ([e4]).into_iter().collect::>() + ); } #[test] @@ -1041,19 +1067,19 @@ mod tests { assert_eq!( get_filtered::>(&mut world), - HashSet::from([e1, e3]) + ([e1, e3]).into_iter().collect::>() ); // ensure changing an entity's archetypes also moves its changed state world.entity_mut(e1).insert(C); - assert_eq!(get_filtered::>(&mut world), HashSet::from([e3, e1]), "changed entities list should not change (although the order will due to archetype moves)"); + assert_eq!(get_filtered::>(&mut world), ([e3, e1]).into_iter().collect::>(), "changed entities list should not change (although the order will due to archetype moves)"); // spawning a new SparseStored entity should not change existing changed state world.entity_mut(e1).insert(SparseStored(0)); assert_eq!( get_filtered::>(&mut world), - HashSet::from([e3, e1]), + ([e3, e1]).into_iter().collect::>(), "changed entities list should not change" ); @@ -1061,7 +1087,7 @@ mod tests { assert!(world.despawn(e2)); assert_eq!( get_filtered::>(&mut world), - HashSet::from([e3, e1]), + ([e3, e1]).into_iter().collect::>(), "changed entities list should not change" ); @@ -1069,7 +1095,7 @@ mod tests { assert!(world.despawn(e1)); assert_eq!( get_filtered::>(&mut world), - HashSet::from([e3]), + ([e3]).into_iter().collect::>(), "e1 should no longer be returned" ); @@ -1082,17 +1108,17 @@ mod tests { world.entity_mut(e4).insert(SparseStored(0)); assert_eq!( get_filtered::>(&mut world), - HashSet::from([e4]) + ([e4]).into_iter().collect::>() ); assert_eq!( get_filtered::>(&mut world), - HashSet::from([e4]) + ([e4]).into_iter().collect::>() ); world.entity_mut(e4).insert(A(1)); assert_eq!( get_filtered::>(&mut world), - HashSet::from([e4]) + ([e4]).into_iter().collect::>() ); world.clear_trackers(); @@ -1104,7 +1130,7 @@ mod tests { assert!(get_filtered::>(&mut world).is_empty()); assert_eq!( get_filtered::>(&mut world), - HashSet::from([e4]) + ([e4]).into_iter().collect::>() ); } @@ -1288,7 +1314,12 @@ mod tests { .iter(&world) .map(|(a, b)| (a.0, b.0)) .collect::>(); - assert_eq!(results, HashSet::from([(1, "1"), (2, "2"), (3, "3"),])); + assert_eq!( + results, + ([(1, "1"), (2, "2"), (3, "3"),]) + .into_iter() + .collect::>() + ); let removed_bundle = world.entity_mut(e2).take::<(B, TableStored)>().unwrap(); assert_eq!(removed_bundle, (B(2), TableStored("2"))); @@ -1297,11 +1328,14 @@ mod tests { .iter(&world) .map(|(a, b)| (a.0, b.0)) .collect::>(); - assert_eq!(results, HashSet::from([(1, "1"), (3, "3"),])); + assert_eq!( + results, + ([(1, "1"), (3, "3"),]).into_iter().collect::>() + ); let mut a_query = world.query::<&A>(); let results = a_query.iter(&world).map(|a| a.0).collect::>(); - assert_eq!(results, HashSet::from([1, 3, 2])); + assert_eq!(results, ([1, 3, 2]).into_iter().collect::>()); let entity_ref = world.entity(e2); assert_eq!( diff --git a/crates/bevy_ecs/src/schedule/graph_utils.rs b/crates/bevy_ecs/src/schedule/graph_utils.rs index a92579ca582936..411f2e68b3faac 100644 --- a/crates/bevy_ecs/src/schedule/graph_utils.rs +++ b/crates/bevy_ecs/src/schedule/graph_utils.rs @@ -116,7 +116,7 @@ impl Default for CheckGraphResults { fn default() -> Self { Self { reachable: FixedBitSet::new(), - connected: HashSet::new(), + connected: HashSet::default(), disconnected: Vec::new(), transitive_edges: Vec::new(), transitive_reduction: DiGraphMap::new(), @@ -150,7 +150,7 @@ where let n = graph.node_count(); // build a copy of the graph where the nodes and edges appear in topsorted order - let mut map = HashMap::with_capacity(n); + let mut map = HashMap::with_capacity_and_hasher(n, Default::default()); let mut topsorted = DiGraphMap::::new(); // iterate nodes in topological order for (i, &node) in topological_order.iter().enumerate() { @@ -163,7 +163,7 @@ where } let mut reachable = FixedBitSet::with_capacity(n * n); - let mut connected = HashSet::new(); + let mut connected = HashSet::default(); let mut disconnected = Vec::new(); let mut transitive_edges = Vec::new(); @@ -272,15 +272,17 @@ where // path of nodes that may form a cycle let mut path = Vec::with_capacity(subgraph.node_count()); // we mark nodes as "blocked" to avoid finding permutations of the same cycles - let mut blocked = HashSet::with_capacity(subgraph.node_count()); + let mut blocked = + HashSet::with_capacity_and_hasher(subgraph.node_count(), Default::default()); // connects nodes along path segments that can't be part of a cycle (given current root) // those nodes can be unblocked at the same time let mut unblock_together: HashMap> = - HashMap::with_capacity(subgraph.node_count()); + HashMap::with_capacity_and_hasher(subgraph.node_count(), Default::default()); // stack for unblocking nodes let mut unblock_stack = Vec::with_capacity(subgraph.node_count()); // nodes can be involved in multiple cycles - let mut maybe_in_more_cycles: HashSet = HashSet::with_capacity(subgraph.node_count()); + let mut maybe_in_more_cycles: HashSet = + HashSet::with_capacity_and_hasher(subgraph.node_count(), Default::default()); // stack for DFS let mut stack = Vec::with_capacity(subgraph.node_count()); diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index d139a1af1361cf..70fd716bc13e83 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -37,7 +37,7 @@ impl Schedules { /// Constructs an empty `Schedules` with zero initial capacity. pub fn new() -> Self { Self { - inner: HashMap::new(), + inner: HashMap::default(), ignored_scheduling_ambiguities: BTreeSet::new(), } } @@ -625,18 +625,18 @@ impl ScheduleGraph { system_conditions: Vec::new(), system_sets: Vec::new(), system_set_conditions: Vec::new(), - system_set_ids: HashMap::new(), + system_set_ids: HashMap::default(), uninit: Vec::new(), hierarchy: Dag::new(), dependency: Dag::new(), ambiguous_with: UnGraphMap::new(), - ambiguous_with_all: HashSet::new(), + ambiguous_with_all: HashSet::default(), conflicting_systems: Vec::new(), anonymous_sets: 0, changed: false, settings: default(), no_sync_edges: BTreeSet::new(), - auto_sync_node_ids: HashMap::new(), + auto_sync_node_ids: HashMap::default(), } } @@ -1148,7 +1148,8 @@ impl ScheduleGraph { // calculate the number of sync points each sync point is from the beginning of the graph // use the same sync point if the distance is the same - let mut distances: HashMap> = HashMap::with_capacity(topo.len()); + let mut distances: HashMap> = + HashMap::with_capacity_and_hasher(topo.len(), Default::default()); for node in &topo { let add_sync_after = self.systems[node.index()].get().unwrap().has_deferred(); @@ -1225,8 +1226,9 @@ impl ScheduleGraph { hierarchy_graph: &GraphMap, ) -> (HashMap>, HashMap) { let mut set_systems: HashMap> = - HashMap::with_capacity(self.system_sets.len()); - let mut set_system_bitsets = HashMap::with_capacity(self.system_sets.len()); + HashMap::with_capacity_and_hasher(self.system_sets.len(), Default::default()); + let mut set_system_bitsets = + HashMap::with_capacity_and_hasher(self.system_sets.len(), Default::default()); for &id in hierarchy_topsort.iter().rev() { if id.is_system() { continue; @@ -1920,7 +1922,7 @@ impl ScheduleGraph { } fn names_of_sets_containing_node(&self, id: &NodeId) -> Vec { - let mut sets = HashSet::new(); + let mut sets = HashSet::default(); self.traverse_sets_containing_node(*id, &mut |set_id| { !self.system_sets[set_id.index()].is_system_type() && sets.insert(set_id) }); diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 7b8dc9465b57ea..9165b01aba7ebc 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -3411,7 +3411,7 @@ unsafe impl DynamicComponentFetch for &'_ HashSet { self, cell: UnsafeEntityCell<'_>, ) -> Result, EntityComponentError> { - let mut ptrs = HashMap::with_capacity(self.len()); + let mut ptrs = HashMap::with_capacity_and_hasher(self.len(), Default::default()); for &id in self { ptrs.insert( id, @@ -3426,7 +3426,7 @@ unsafe impl DynamicComponentFetch for &'_ HashSet { self, cell: UnsafeEntityCell<'_>, ) -> Result, EntityComponentError> { - let mut ptrs = HashMap::with_capacity(self.len()); + let mut ptrs = HashMap::with_capacity_and_hasher(self.len(), Default::default()); for &id in self { ptrs.insert( id, diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 00e175cd77e17d..9f3b6eeaa0dec4 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -3044,7 +3044,7 @@ impl World { /// // probably use something like `ReflectFromPtr` in a real-world scenario. /// /// // Create the hash map that will store the closures for each resource type - /// let mut closures: HashMap)>> = HashMap::new(); + /// let mut closures: HashMap)>> = HashMap::default(); /// /// // Add closure for `A` /// closures.insert(TypeId::of::(), Box::new(|ptr| { @@ -3121,7 +3121,7 @@ impl World { /// // probably use something like `ReflectFromPtr` in a real-world scenario. /// /// // Create the hash map that will store the mutator closures for each resource type - /// let mut mutators: HashMap)>> = HashMap::new(); + /// let mut mutators: HashMap)>> = HashMap::default(); /// /// // Add mutator closure for `A` /// mutators.insert(TypeId::of::(), Box::new(|mut_untyped| { @@ -3879,38 +3879,46 @@ mod tests { let baz_id = TypeId::of::(); assert_eq!( to_type_ids(world.inspect_entity(ent0).collect()), - [Some(foo_id), Some(bar_id), Some(baz_id)].into() + [Some(foo_id), Some(bar_id), Some(baz_id)] + .into_iter() + .collect::>() ); assert_eq!( to_type_ids(world.inspect_entity(ent1).collect()), - [Some(foo_id), Some(bar_id)].into() + [Some(foo_id), Some(bar_id)] + .into_iter() + .collect::>() ); assert_eq!( to_type_ids(world.inspect_entity(ent2).collect()), - [Some(bar_id), Some(baz_id)].into() + [Some(bar_id), Some(baz_id)] + .into_iter() + .collect::>() ); assert_eq!( to_type_ids(world.inspect_entity(ent3).collect()), - [Some(foo_id), Some(baz_id)].into() + [Some(foo_id), Some(baz_id)] + .into_iter() + .collect::>() ); assert_eq!( to_type_ids(world.inspect_entity(ent4).collect()), - [Some(foo_id)].into() + [Some(foo_id)].into_iter().collect::>() ); assert_eq!( to_type_ids(world.inspect_entity(ent5).collect()), - [Some(bar_id)].into() + [Some(bar_id)].into_iter().collect::>() ); assert_eq!( to_type_ids(world.inspect_entity(ent6).collect()), - [Some(baz_id)].into() + [Some(baz_id)].into_iter().collect::>() ); } #[test] fn iterate_entities() { let mut world = World::new(); - let mut entity_counters = HashMap::new(); + let mut entity_counters = HashMap::default(); let iterate_and_count_entities = |world: &World, entity_counters: &mut HashMap<_, _>| { entity_counters.clear(); diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 6d224a11c651d3..a93cc2165b272d 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -262,11 +262,11 @@ async fn load_gltf<'a, 'b, 'c>( #[cfg(feature = "bevy_animation")] let paths = { - let mut paths = HashMap::)>::new(); + let mut paths = HashMap::)>::default(); for scene in gltf.scenes() { for node in scene.nodes() { let root_index = node.index(); - paths_recur(node, &[], &mut paths, root_index, &mut HashSet::new()); + paths_recur(node, &[], &mut paths, root_index, &mut HashSet::default()); } } paths @@ -747,8 +747,8 @@ async fn load_gltf<'a, 'b, 'c>( }) .collect(); - let mut nodes = HashMap::>::new(); - let mut named_nodes = HashMap::new(); + let mut nodes = HashMap::>::default(); + let mut named_nodes = HashMap::default(); let mut skins = vec![]; let mut named_skins = HashMap::default(); for node in GltfTreeIterator::try_new(&gltf)? { @@ -817,7 +817,7 @@ async fn load_gltf<'a, 'b, 'c>( for scene in gltf.scenes() { let mut err = None; let mut world = World::default(); - let mut node_index_to_entity_map = HashMap::new(); + let mut node_index_to_entity_map = HashMap::default(); let mut entity_to_skin_index_map = EntityHashMap::default(); let mut scene_load_context = load_context.begin_labeled_asset(); @@ -1866,7 +1866,7 @@ impl<'a> GltfTreeIterator<'a> { .collect::>(); let mut nodes = Vec::new(); - let mut warned_about_max_joints = HashSet::new(); + let mut warned_about_max_joints = HashSet::default(); while let Some(index) = empty_children.pop_front() { if let Some(skin) = unprocessed_nodes.get(&index).unwrap().0.skin() { if skin.joints().len() > MAX_JOINTS && warned_about_max_joints.insert(skin.index()) diff --git a/crates/bevy_mesh/src/primitives/dim2.rs b/crates/bevy_mesh/src/primitives/dim2.rs index a8b3237b7a80bd..d15d3b72c4d13d 100644 --- a/crates/bevy_mesh/src/primitives/dim2.rs +++ b/crates/bevy_mesh/src/primitives/dim2.rs @@ -1059,7 +1059,7 @@ mod tests { use crate::{Mesh, MeshBuilder, Meshable, VertexAttributeValues}; fn count_distinct_positions(points: &[[f32; 3]]) -> usize { - let mut map = HashSet::new(); + let mut map = HashSet::default(); for point in points { map.insert(point.map(FloatOrd)); } diff --git a/crates/bevy_pbr/src/light_probe/mod.rs b/crates/bevy_pbr/src/light_probe/mod.rs index dca5d7209e9b54..d1286288a271b8 100644 --- a/crates/bevy_pbr/src/light_probe/mod.rs +++ b/crates/bevy_pbr/src/light_probe/mod.rs @@ -631,7 +631,7 @@ where fn new() -> RenderViewLightProbes { RenderViewLightProbes { binding_index_to_textures: vec![], - cubemap_to_binding_index: HashMap::new(), + cubemap_to_binding_index: HashMap::default(), render_light_probes: vec![], view_light_probe_info: C::ViewLightProbeInfo::default(), } diff --git a/crates/bevy_pbr/src/meshlet/from_mesh.rs b/crates/bevy_pbr/src/meshlet/from_mesh.rs index b8cdd1fc1144d2..0468c715f2a873 100644 --- a/crates/bevy_pbr/src/meshlet/from_mesh.rs +++ b/crates/bevy_pbr/src/meshlet/from_mesh.rs @@ -212,7 +212,7 @@ fn find_connected_meshlets( meshlets: &Meshlets, ) -> Vec> { // For each edge, gather all meshlets that use it - let mut edges_to_meshlets = HashMap::new(); + let mut edges_to_meshlets = HashMap::default(); for meshlet_id in simplification_queue.clone() { let meshlet = meshlets.get(meshlet_id); @@ -235,7 +235,7 @@ fn find_connected_meshlets( } // For each meshlet pair, count how many edges they share - let mut shared_edge_count = HashMap::new(); + let mut shared_edge_count = HashMap::default(); for (_, meshlet_ids) in edges_to_meshlets { for (meshlet_id1, meshlet_id2) in meshlet_ids.into_iter().tuple_combinations() { diff --git a/crates/bevy_pbr/src/meshlet/instance_manager.rs b/crates/bevy_pbr/src/meshlet/instance_manager.rs index 768864fe6b6103..9de3e8c25a4859 100644 --- a/crates/bevy_pbr/src/meshlet/instance_manager.rs +++ b/crates/bevy_pbr/src/meshlet/instance_manager.rs @@ -71,8 +71,8 @@ impl InstanceManager { view_instance_visibility: EntityHashMap::default(), next_material_id: 0, - material_id_lookup: HashMap::new(), - material_ids_present_in_scene: HashSet::new(), + material_id_lookup: HashMap::default(), + material_ids_present_in_scene: HashSet::default(), } } diff --git a/crates/bevy_pbr/src/meshlet/meshlet_mesh_manager.rs b/crates/bevy_pbr/src/meshlet/meshlet_mesh_manager.rs index 831fe11fb353bf..05799da34f3b0b 100644 --- a/crates/bevy_pbr/src/meshlet/meshlet_mesh_manager.rs +++ b/crates/bevy_pbr/src/meshlet/meshlet_mesh_manager.rs @@ -42,7 +42,7 @@ impl FromWorld for MeshletMeshManager { "meshlet_bounding_spheres", render_device, ), - meshlet_mesh_slices: HashMap::new(), + meshlet_mesh_slices: HashMap::default(), } } } diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 1f8836ff87b2f0..4239a3cb940a4d 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -954,7 +954,7 @@ pub fn extract_meshes_for_cpu_building( render_mesh_instances.clear(); for queue in render_mesh_instance_queues.iter_mut() { for (entity, render_mesh_instance) in queue.drain(..) { - render_mesh_instances.insert_unique_unchecked(entity, render_mesh_instance); + render_mesh_instances.insert(entity, render_mesh_instance); } } } diff --git a/crates/bevy_picking/src/focus.rs b/crates/bevy_picking/src/focus.rs index d07c0c095f4bc5..8c3246d96ea9ab 100644 --- a/crates/bevy_picking/src/focus.rs +++ b/crates/bevy_picking/src/focus.rs @@ -226,7 +226,7 @@ pub fn update_interactions( // need to be able to insert the interaction component on entities if they do not exist. To do // so we need to know the final aggregated interaction state to avoid the scenario where we set // an entity to `Pressed`, then overwrite that with a lower precedent like `Hovered`. - let mut new_interaction_state = HashMap::::new(); + let mut new_interaction_state = HashMap::::default(); for (pointer, pointer_press, mut pointer_interaction) in &mut pointers { if let Some(pointers_hovered_entities) = hover_map.get(pointer) { // Insert a sorted list of hit entities into the pointer's interaction component. diff --git a/crates/bevy_reflect/Cargo.toml b/crates/bevy_reflect/Cargo.toml index 2d7fff5e7c3582..0b23091222608f 100644 --- a/crates/bevy_reflect/Cargo.toml +++ b/crates/bevy_reflect/Cargo.toml @@ -26,7 +26,7 @@ debug_stack = [] documentation = ["bevy_reflect_derive/documentation"] # Enables function reflection functions = ["bevy_reflect_derive/functions"] -alloc = [] +alloc = ["bevy_utils/alloc"] [dependencies] # bevy diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 60704d602accbd..8b06b21d596e0f 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -823,6 +823,7 @@ macro_rules! impl_reflect_for_hashmap { } impl_reflect_for_hashmap!(::std::collections::HashMap); +impl_type_path!(::std::hash::BuildHasherDefault); impl_type_path!(::std::collections::hash_map::RandomState); impl_type_path!(::std::collections::HashMap); #[cfg(feature = "functions")] @@ -835,7 +836,8 @@ crate::func::macros::impl_function_traits!(::std::collections::HashMap; ); impl_reflect_for_hashmap!(bevy_utils::hashbrown::HashMap); -impl_type_path!(::bevy_utils::hashbrown::hash_map::DefaultHashBuilder); +impl_type_path!(::bevy_utils::AHasher); +impl_type_path!(::bevy_utils::hashbrown::DefaultHashBuilder); impl_type_path!(::bevy_utils::hashbrown::HashMap); #[cfg(feature = "functions")] crate::func::macros::impl_function_traits!(::bevy_utils::hashbrown::HashMap; @@ -2318,10 +2320,10 @@ mod tests { #[test] fn should_partial_eq_hash_map() { - let mut a = HashMap::new(); + let mut a = HashMap::default(); a.insert(0usize, 1.23_f64); let b = a.clone(); - let mut c = HashMap::new(); + let mut c = HashMap::default(); c.insert(0usize, 3.21_f64); let a: &dyn PartialReflect = &a; diff --git a/crates/bevy_reflect/src/kind.rs b/crates/bevy_reflect/src/kind.rs index 2e3928162a73f5..4345a21fd93a3c 100644 --- a/crates/bevy_reflect/src/kind.rs +++ b/crates/bevy_reflect/src/kind.rs @@ -296,7 +296,7 @@ mod tests { #[test] fn should_cast_mut() { - let mut value: HashSet = HashSet::new(); + let mut value: HashSet = HashSet::default(); let result = value.reflect_mut().as_set(); assert!(result.is_ok()); diff --git a/crates/bevy_reflect/src/lib.rs b/crates/bevy_reflect/src/lib.rs index 6931309a54417c..f7f7d2e2b5df4a 100644 --- a/crates/bevy_reflect/src/lib.rs +++ b/crates/bevy_reflect/src/lib.rs @@ -1483,7 +1483,11 @@ mod tests { assert!(fields[0].reflect_partial_eq(&123_i32).unwrap_or_default()); assert!(fields[1].reflect_partial_eq(&321_i32).unwrap_or_default()); - let mut map_value: Box = Box::new(HashMap::from([(123_i32, 321_i32)])); + let mut map_value: Box = Box::new( + ([(123_i32, 321_i32)]) + .into_iter() + .collect::>(), + ); let fields = map_value.drain(); assert!(fields[0].0.reflect_partial_eq(&123_i32).unwrap_or_default()); assert!(fields[0].1.reflect_partial_eq(&321_i32).unwrap_or_default()); @@ -1847,7 +1851,7 @@ mod tests { assert_eq!(usize::type_path(), info.key_ty().path()); assert_eq!(f32::type_path(), info.value_ty().path()); - let value: &dyn Reflect = &MyMap::new(); + let value: &dyn Reflect = &MyMap::default(); let info = value.reflect_type_info(); assert!(info.is::()); @@ -2111,7 +2115,7 @@ mod tests { } } - let mut map = HashMap::new(); + let mut map = HashMap::default(); map.insert(123, 1.23); let test = Test { @@ -2425,7 +2429,7 @@ bevy_reflect::tests::Test { // test reflected value value: u32, } - let mut map = HashMap::new(); + let mut map = HashMap::default(); map.insert(9, 10); let mut test_struct: DynamicStruct = TestStruct { tuple: (0, 1), diff --git a/crates/bevy_reflect/src/map.rs b/crates/bevy_reflect/src/map.rs index ffb56a7b0292eb..e2221bd2eac2e3 100644 --- a/crates/bevy_reflect/src/map.rs +++ b/crates/bevy_reflect/src/map.rs @@ -566,7 +566,7 @@ pub fn map_partial_eq(a: &M, b: &dyn PartialReflect) -> Option< /// # use bevy_utils::HashMap; /// use bevy_reflect::Reflect; /// -/// let mut my_map = HashMap::new(); +/// let mut my_map = HashMap::default(); /// my_map.insert(123, String::from("Hello")); /// println!("{:#?}", &my_map as &dyn Reflect); /// diff --git a/crates/bevy_reflect/src/serde/de/mod.rs b/crates/bevy_reflect/src/serde/de/mod.rs index 92a43ed17565d9..95506bd53993e1 100644 --- a/crates/bevy_reflect/src/serde/de/mod.rs +++ b/crates/bevy_reflect/src/serde/de/mod.rs @@ -143,10 +143,10 @@ mod tests { } fn get_my_struct() -> MyStruct { - let mut map = HashMap::new(); + let mut map = HashMap::default(); map.insert(64, 32); - let mut set = HashSet::new(); + let mut set = HashSet::default(); set.insert(64); MyStruct { diff --git a/crates/bevy_reflect/src/serde/ser/mod.rs b/crates/bevy_reflect/src/serde/ser/mod.rs index ead36d4819898a..f90030455b2ede 100644 --- a/crates/bevy_reflect/src/serde/ser/mod.rs +++ b/crates/bevy_reflect/src/serde/ser/mod.rs @@ -124,10 +124,10 @@ mod tests { } fn get_my_struct() -> MyStruct { - let mut map = HashMap::new(); + let mut map = HashMap::default(); map.insert(64, 32); - let mut set = HashSet::new(); + let mut set = HashSet::default(); set.insert(64); MyStruct { diff --git a/crates/bevy_reflect/src/set.rs b/crates/bevy_reflect/src/set.rs index 50c5a752d920c3..ea8dde7c83cfda 100644 --- a/crates/bevy_reflect/src/set.rs +++ b/crates/bevy_reflect/src/set.rs @@ -434,7 +434,7 @@ pub fn set_partial_eq(a: &M, b: &dyn PartialReflect) -> Option { /// # use bevy_utils::HashSet; /// use bevy_reflect::Reflect; /// -/// let mut my_set = HashSet::new(); +/// let mut my_set = HashSet::default(); /// my_set.insert(String::from("Hello")); /// println!("{:#?}", &my_set as &dyn Reflect); /// diff --git a/crates/bevy_remote/src/builtin_methods.rs b/crates/bevy_remote/src/builtin_methods.rs index 08458da1c02cfd..93015fc0799957 100644 --- a/crates/bevy_remote/src/builtin_methods.rs +++ b/crates/bevy_remote/src/builtin_methods.rs @@ -847,7 +847,7 @@ fn build_components_map<'a>( paths_and_reflect_components: impl Iterator, type_registry: &TypeRegistry, ) -> AnyhowResult> { - let mut serialized_components_map = HashMap::new(); + let mut serialized_components_map = HashMap::default(); for (type_path, reflect_component) in paths_and_reflect_components { let Some(reflected) = reflect_component.reflect(entity_ref.clone()) else { @@ -873,7 +873,7 @@ fn build_has_map<'a>( entity_ref: FilteredEntityRef, paths_and_reflect_components: impl Iterator, ) -> HashMap { - let mut has_map = HashMap::new(); + let mut has_map = HashMap::default(); for (type_path, reflect_component) in paths_and_reflect_components { let has = reflect_component.contains(entity_ref.clone()); diff --git a/crates/bevy_remote/src/http.rs b/crates/bevy_remote/src/http.rs index 1b725ffab36a54..4d0059bc084599 100644 --- a/crates/bevy_remote/src/http.rs +++ b/crates/bevy_remote/src/http.rs @@ -57,7 +57,7 @@ impl Headers { /// Create a new instance of `Headers`. pub fn new() -> Self { Self { - headers: HashMap::new(), + headers: HashMap::default(), } } diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 58fda6529c891e..97faa07f93cd58 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -885,7 +885,7 @@ pub fn camera_system( ) { let primary_window = primary_window.iter().next(); - let mut changed_window_ids = HashSet::new(); + let mut changed_window_ids = HashSet::default(); changed_window_ids.extend(window_created_events.read().map(|event| event.window)); changed_window_ids.extend(window_resized_events.read().map(|event| event.window)); let scale_factor_changed_window_ids: HashSet<_> = window_scale_factor_changed_events @@ -924,7 +924,9 @@ pub fn camera_system( // This can happen when the window is moved between monitors with different DPIs. // Without this, the viewport will take a smaller portion of the window moved to // a higher DPI monitor. - if normalized_target.is_changed(&scale_factor_changed_window_ids, &HashSet::new()) { + if normalized_target + .is_changed(&scale_factor_changed_window_ids, &HashSet::default()) + { if let (Some(new_scale_factor), Some(old_scale_factor)) = ( new_computed_target_info .as_ref() @@ -1164,8 +1166,8 @@ pub fn sort_cameras( ord => ord, }); let mut previous_order_target = None; - let mut ambiguities = HashSet::new(); - let mut target_counts = HashMap::new(); + let mut ambiguities = HashSet::default(); + let mut target_counts = HashMap::default(); for sorted_camera in &mut sorted_cameras.0 { let new_order_target = (sorted_camera.order, sorted_camera.target.clone()); if let Some(previous_order_target) = previous_order_target { diff --git a/crates/bevy_render/src/camera/camera_driver_node.rs b/crates/bevy_render/src/camera/camera_driver_node.rs index f01d7814787833..6131ba86738ee0 100644 --- a/crates/bevy_render/src/camera/camera_driver_node.rs +++ b/crates/bevy_render/src/camera/camera_driver_node.rs @@ -32,7 +32,7 @@ impl Node for CameraDriverNode { ) -> Result<(), NodeRunError> { let sorted_cameras = world.resource::(); let windows = world.resource::(); - let mut camera_windows = HashSet::new(); + let mut camera_windows = HashSet::default(); for sorted_camera in &sorted_cameras.0 { let Ok(camera) = self.cameras.get_manual(world, sorted_camera.entity) else { continue; diff --git a/crates/bevy_render/src/mesh/allocator.rs b/crates/bevy_render/src/mesh/allocator.rs index 3493f7dcf17226..ac3ebd8a0de9da 100644 --- a/crates/bevy_render/src/mesh/allocator.rs +++ b/crates/bevy_render/src/mesh/allocator.rs @@ -327,10 +327,10 @@ impl FromWorld for MeshAllocator { .contains(DownlevelFlags::BASE_VERTEX); Self { - slabs: HashMap::new(), - slab_layouts: HashMap::new(), - mesh_id_to_vertex_slab: HashMap::new(), - mesh_id_to_index_slab: HashMap::new(), + slabs: HashMap::default(), + slab_layouts: HashMap::default(), + mesh_id_to_vertex_slab: HashMap::default(), + mesh_id_to_index_slab: HashMap::default(), next_slab_id: SlabId(0), general_vertex_slabs_supported, } @@ -585,7 +585,7 @@ impl MeshAllocator { } fn free_meshes(&mut self, extracted_meshes: &ExtractedAssets) { - let mut empty_slabs = HashSet::new(); + let mut empty_slabs = HashSet::default(); for mesh_id in &extracted_meshes.removed { if let Some(slab_id) = self.mesh_id_to_vertex_slab.remove(mesh_id) { self.free_allocation_in_slab(mesh_id, slab_id, &mut empty_slabs); @@ -866,8 +866,8 @@ impl GeneralSlab { let mut new_slab = GeneralSlab { allocator: Allocator::new(slab_slot_capacity), buffer: None, - resident_allocations: HashMap::new(), - pending_allocations: HashMap::new(), + resident_allocations: HashMap::default(), + pending_allocations: HashMap::default(), element_layout: layout, slot_capacity: slab_slot_capacity, }; diff --git a/crates/bevy_render/src/render_asset.rs b/crates/bevy_render/src/render_asset.rs index 9fc802ed85503f..c0cf1554e67d77 100644 --- a/crates/bevy_render/src/render_asset.rs +++ b/crates/bevy_render/src/render_asset.rs @@ -234,7 +234,7 @@ pub(crate) fn extract_render_asset( } let mut extracted_assets = Vec::new(); - let mut added = HashSet::new(); + let mut added = HashSet::default(); for id in changed_assets.drain() { if let Some(asset) = assets.get(id) { let asset_usage = A::asset_usage(asset); diff --git a/crates/bevy_render/src/render_resource/pipeline_cache.rs b/crates/bevy_render/src/render_resource/pipeline_cache.rs index 1cb64d06bff32c..12b8b6aa388503 100644 --- a/crates/bevy_render/src/render_resource/pipeline_cache.rs +++ b/crates/bevy_render/src/render_resource/pipeline_cache.rs @@ -733,7 +733,7 @@ impl PipelineCache { // TODO: Expose this somehow let compilation_options = PipelineCompilationOptions { - constants: &std::collections::HashMap::new(), + constants: &std::collections::HashMap::default(), zero_initialize_workgroup_memory: false, vertex_pulling_transform: Default::default(), }; @@ -815,7 +815,7 @@ impl PipelineCache { entry_point: &descriptor.entry_point, // TODO: Expose this somehow compilation_options: PipelineCompilationOptions { - constants: &std::collections::HashMap::new(), + constants: &std::collections::HashMap::default(), zero_initialize_workgroup_memory: false, vertex_pulling_transform: Default::default(), }, diff --git a/crates/bevy_render/src/render_resource/pipeline_specializer.rs b/crates/bevy_render/src/render_resource/pipeline_specializer.rs index 7656fd57d67292..c804ec4b792928 100644 --- a/crates/bevy_render/src/render_resource/pipeline_specializer.rs +++ b/crates/bevy_render/src/render_resource/pipeline_specializer.rs @@ -10,9 +10,12 @@ use bevy_utils::{ default, hashbrown::hash_map::{RawEntryMut, VacantEntry}, tracing::error, - Entry, HashMap, + AHasher, Entry, HashMap, +}; +use core::{ + fmt::Debug, + hash::{BuildHasherDefault, Hash}, }; -use core::{fmt::Debug, hash::Hash}; use derive_more::derive::{Display, Error, From}; pub trait SpecializedRenderPipeline { @@ -132,7 +135,11 @@ impl SpecializedMeshPipelines { specialize_pipeline: &S, key: S::Key, layout: &MeshVertexBufferLayoutRef, - entry: VacantEntry<(MeshVertexBufferLayoutRef, S::Key), CachedRenderPipelineId>, + entry: VacantEntry< + (MeshVertexBufferLayoutRef, S::Key), + CachedRenderPipelineId, + BuildHasherDefault, + >, ) -> Result where S: SpecializedMeshPipeline, diff --git a/crates/bevy_scene/src/scene_filter.rs b/crates/bevy_scene/src/scene_filter.rs index eb86984903c795..3748525f6ec1b0 100644 --- a/crates/bevy_scene/src/scene_filter.rs +++ b/crates/bevy_scene/src/scene_filter.rs @@ -47,7 +47,7 @@ impl SceneFilter { /// /// [`Denylist`]: SceneFilter::Denylist pub fn allow_all() -> Self { - Self::Denylist(HashSet::new()) + Self::Denylist(HashSet::default()) } /// Creates a filter where all types are denied. @@ -56,7 +56,7 @@ impl SceneFilter { /// /// [`Allowlist`]: SceneFilter::Allowlist pub fn deny_all() -> Self { - Self::Allowlist(HashSet::new()) + Self::Allowlist(HashSet::default()) } /// Allow the given type, `T`. @@ -88,7 +88,7 @@ impl SceneFilter { pub fn allow_by_id(mut self, type_id: TypeId) -> Self { match &mut self { Self::Unset => { - self = Self::Allowlist(HashSet::from([type_id])); + self = Self::Allowlist([type_id].into_iter().collect()); } Self::Allowlist(list) => { list.insert(type_id); @@ -128,7 +128,7 @@ impl SceneFilter { #[must_use] pub fn deny_by_id(mut self, type_id: TypeId) -> Self { match &mut self { - Self::Unset => self = Self::Denylist(HashSet::from([type_id])), + Self::Unset => self = Self::Denylist([type_id].into_iter().collect()), Self::Allowlist(list) => { list.remove(&type_id); } @@ -222,7 +222,7 @@ impl IntoIterator for SceneFilter { fn into_iter(self) -> Self::IntoIter { match self { - Self::Unset => HashSet::new().into_iter(), + Self::Unset => HashSet::default().into_iter(), Self::Allowlist(list) | Self::Denylist(list) => list.into_iter(), } } diff --git a/crates/bevy_scene/src/scene_spawner.rs b/crates/bevy_scene/src/scene_spawner.rs index e192aa4324be85..0c3febbc9435d4 100644 --- a/crates/bevy_scene/src/scene_spawner.rs +++ b/crates/bevy_scene/src/scene_spawner.rs @@ -316,7 +316,7 @@ impl SceneSpawner { let spawned = self .spawned_dynamic_scenes .entry(handle.id()) - .or_insert_with(HashSet::new); + .or_insert_with(HashSet::default); spawned.insert(instance_id); // Scenes with parents need more setup before they are ready. diff --git a/crates/bevy_scene/src/serde.rs b/crates/bevy_scene/src/serde.rs index 0cf4efa128fffe..631865aa9fde78 100644 --- a/crates/bevy_scene/src/serde.rs +++ b/crates/bevy_scene/src/serde.rs @@ -476,7 +476,7 @@ impl<'a, 'de> Visitor<'de> for SceneMapVisitor<'a> { where A: MapAccess<'de>, { - let mut added = HashSet::new(); + let mut added = HashSet::default(); let mut entries = Vec::new(); while let Some(registration) = map.next_key_seed(TypeRegistrationDeserializer::new(self.registry))? diff --git a/crates/bevy_ui/src/stack.rs b/crates/bevy_ui/src/stack.rs index a8d535fa2ff277..9bb50fafc81b10 100644 --- a/crates/bevy_ui/src/stack.rs +++ b/crates/bevy_ui/src/stack.rs @@ -59,7 +59,7 @@ pub fn ui_stack_system( maybe_zindex.map(|zindex| zindex.0).unwrap_or(0), ), )); - visited_root_nodes.insert_unique_unchecked(id); + visited_root_nodes.insert(id); } for (id, global_zindex, maybe_zindex) in zindex_global_node_query.iter() { diff --git a/crates/bevy_ui/src/update.rs b/crates/bevy_ui/src/update.rs index e9b3329aa8203c..e057b44072414b 100644 --- a/crates/bevy_ui/src/update.rs +++ b/crates/bevy_ui/src/update.rs @@ -109,7 +109,7 @@ pub fn update_target_camera_system( ) { // Track updated entities to prevent redundant updates, as `Commands` changes are deferred, // and updates done for changed_children_query can overlap with itself or with root_node_query - let mut updated_entities = HashSet::new(); + let mut updated_entities = HashSet::default(); // Assuming that TargetCamera is manually set on the root node only, // update root nodes first, since it implies the biggest change diff --git a/crates/bevy_utils/Cargo.toml b/crates/bevy_utils/Cargo.toml index c1555d8ba94bb0..6b46f779463fa9 100644 --- a/crates/bevy_utils/Cargo.toml +++ b/crates/bevy_utils/Cargo.toml @@ -26,7 +26,7 @@ ahash = { version = "0.8.7", default-features = false, features = [ "compile-time-rng", ] } tracing = { version = "0.1", default-features = false } -hashbrown = { version = "0.14.2", default-features = false } +hashbrown = { version = "0.15.0", default-features = false } bevy_utils_proc_macros = { version = "0.15.0-dev", path = "macros" } thread_local = { version = "1.0", optional = true } diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index 1f7e1f7e5c32b1..6b255801ede4a9 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -447,8 +447,8 @@ mod tests { fn stable_hash_within_same_program_execution() { use alloc::vec::Vec; - let mut map_1 = HashMap::new(); - let mut map_2 = HashMap::new(); + let mut map_1 = HashMap::default(); + let mut map_2 = HashMap::default(); for i in 1..10 { map_1.insert(i, i); map_2.insert(i, i); diff --git a/examples/3d/tonemapping.rs b/examples/3d/tonemapping.rs index b8aef70c2fd345..68c4c43474fc13 100644 --- a/examples/3d/tonemapping.rs +++ b/examples/3d/tonemapping.rs @@ -578,7 +578,7 @@ impl PerMethodSettings { impl Default for PerMethodSettings { fn default() -> Self { - let mut settings = HashMap::new(); + let mut settings = HashMap::default(); for method in [ Tonemapping::None, diff --git a/examples/animation/animation_masks.rs b/examples/animation/animation_masks.rs index 0ea939d2eb0d87..3f4fee511d71b4 100644 --- a/examples/animation/animation_masks.rs +++ b/examples/animation/animation_masks.rs @@ -4,8 +4,8 @@ use bevy::{ animation::{AnimationTarget, AnimationTargetId}, color::palettes::css::{LIGHT_GRAY, WHITE}, prelude::*, - utils::hashbrown::HashSet, }; +use std::collections::HashSet; // IDs of the mask groups we define for the running fox model. // diff --git a/examples/ecs/dynamic.rs b/examples/ecs/dynamic.rs index 7cec3a47fdd89d..ad4f4ad65df8fc 100644 --- a/examples/ecs/dynamic.rs +++ b/examples/ecs/dynamic.rs @@ -3,7 +3,7 @@ //! This example show how you can create components dynamically, spawn entities with those components //! as well as query for entities with those components. -use std::{alloc::Layout, io::Write, ptr::NonNull}; +use std::{alloc::Layout, collections::HashMap, io::Write, ptr::NonNull}; use bevy::{ ecs::{ @@ -13,7 +13,6 @@ use bevy::{ }, prelude::*, ptr::{Aligned, OwningPtr}, - utils::HashMap, }; const PROMPT: &str = " diff --git a/examples/games/contributors.rs b/examples/games/contributors.rs index 2f595fda4ab406..b0c0607cb2e325 100644 --- a/examples/games/contributors.rs +++ b/examples/games/contributors.rs @@ -327,7 +327,7 @@ fn contributors() -> Result { // Take the list of commit author names and collect them into a HashMap, // keeping a count of how many commits they authored. let contributors = BufReader::new(stdout).lines().map_while(Result::ok).fold( - HashMap::new(), + HashMap::default(), |mut acc, word| { *acc.entry(word).or_insert(0) += 1; acc diff --git a/examples/reflection/dynamic_types.rs b/examples/reflection/dynamic_types.rs index c892bc83de4a76..387fe7d0ed34d0 100644 --- a/examples/reflection/dynamic_types.rs +++ b/examples/reflection/dynamic_types.rs @@ -195,7 +195,7 @@ fn main() { dynamic_set.remove(&"y"); - let mut my_set: HashSet<&str> = HashSet::new(); + let mut my_set: HashSet<&str> = HashSet::default(); my_set.apply(&dynamic_set); assert_eq!(my_set, HashSet::from_iter(["x", "z"])); } @@ -204,7 +204,7 @@ fn main() { { let dynamic_map = DynamicMap::from_iter([("x", 1u32), ("y", 2u32), ("z", 3u32)]); - let mut my_map: HashMap<&str, u32> = HashMap::new(); + let mut my_map: HashMap<&str, u32> = HashMap::default(); my_map.apply(&dynamic_map); assert_eq!(my_map.get("x"), Some(&1)); assert_eq!(my_map.get("y"), Some(&2)); diff --git a/tests/ecs/ambiguity_detection.rs b/tests/ecs/ambiguity_detection.rs index f6971b1ca2b23d..2e2de0721bf686 100644 --- a/tests/ecs/ambiguity_detection.rs +++ b/tests/ecs/ambiguity_detection.rs @@ -71,7 +71,7 @@ fn configure_ambiguity_detection(sub_app: &mut SubApp) { /// Returns the number of conflicting systems per schedule. fn count_ambiguities(sub_app: &SubApp) -> AmbiguitiesCount { let schedules = sub_app.world().resource::(); - let mut ambiguities = HashMap::new(); + let mut ambiguities = HashMap::default(); for (_, schedule) in schedules.iter() { let ambiguities_in_schedule = schedule.graph().conflicting_systems().len(); ambiguities.insert(schedule.label(), ambiguities_in_schedule); diff --git a/tools/build-templated-pages/Cargo.toml b/tools/build-templated-pages/Cargo.toml index b65f1bd358ac46..d19e553dd37812 100644 --- a/tools/build-templated-pages/Cargo.toml +++ b/tools/build-templated-pages/Cargo.toml @@ -12,7 +12,7 @@ toml_edit = { version = "0.22.7", default-features = false, features = [ tera = "1.15" serde = { version = "1.0", features = ["derive"] } bitflags = "2.3" -hashbrown = { version = "0.14", features = ["serde"] } +hashbrown = { version = "0.15", features = ["serde"] } [lints] workspace = true