Move hashbrown and foldhash out of bevy_utils (#17460)

# Objective

- Contributes to #16877

## Solution

- Moved `hashbrown`, `foldhash`, and related types out of `bevy_utils`
and into `bevy_platform_support`
- Refactored the above to match the layout of these types in `std`.
- Updated crates as required.

## Testing

- CI

---

## Migration Guide

- The following items were moved out of `bevy_utils` and into
`bevy_platform_support::hash`:
  - `FixedState`
  - `DefaultHasher`
  - `RandomState`
  - `FixedHasher`
  - `Hashed`
  - `PassHash`
  - `PassHasher`
  - `NoOpHash`
- The following items were moved out of `bevy_utils` and into
`bevy_platform_support::collections`:
  - `HashMap`
  - `HashSet`
- `bevy_utils::hashbrown` has been removed. Instead, import from
`bevy_platform_support::collections` _or_ take a dependency on
`hashbrown` directly.
- `bevy_utils::Entry` has been removed. Instead, import from
`bevy_platform_support::collections::hash_map` or
`bevy_platform_support::collections::hash_set` as appropriate.
- All of the above equally apply to `bevy::utils` and
`bevy::platform_support`.

## Notes

- I left `PreHashMap`, `PreHashMapExt`, and `TypeIdMap` in `bevy_utils`
as they might be candidates for micro-crating. They can always be moved
into `bevy_platform_support` at a later date if desired.
This commit is contained in:
Zachary Harrold 2025-01-24 03:46:08 +11:00 committed by GitHub
parent 04990fcd27
commit 9bc0ae33c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
175 changed files with 595 additions and 443 deletions

View File

@ -24,6 +24,9 @@ bevy_reflect = { path = "../crates/bevy_reflect", features = ["functions"] }
bevy_render = { path = "../crates/bevy_render" }
bevy_tasks = { path = "../crates/bevy_tasks" }
bevy_utils = { path = "../crates/bevy_utils" }
bevy_platform_support = { path = "../crates/bevy_platform_support", default-features = false, features = [
"std",
] }
# Other crates
glam = "0.29"

View File

@ -1,8 +1,8 @@
use core::{fmt::Write, hint::black_box, iter, time::Duration};
use benches::bench;
use bevy_platform_support::collections::HashMap;
use bevy_reflect::{DynamicMap, Map};
use bevy_utils::HashMap;
use criterion::{
criterion_group, measurement::Measurement, AxisScale, BatchSize, BenchmarkGroup, BenchmarkId,
Criterion, PlotConfiguration, Throughput,

View File

@ -25,6 +25,10 @@ bevy_time = { path = "../bevy_time", version = "0.16.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"std",
"serialize",
] }
# other
petgraph = { version = "0.6", features = ["serde-1"] }

View File

@ -89,21 +89,20 @@ use core::{
marker::PhantomData,
};
use crate::{
graph::AnimationNodeIndex,
prelude::{Animatable, BlendInput},
AnimationEntityMut, AnimationEvaluationError,
};
use bevy_ecs::component::{Component, Mutable};
use bevy_math::curve::{
cores::{UnevenCore, UnevenCoreError},
iterable::IterableCurve,
Curve, Interval,
};
use bevy_platform_support::hash::Hashed;
use bevy_reflect::{FromReflect, Reflect, Reflectable, TypeInfo, Typed};
use bevy_render::mesh::morph::MorphWeights;
use crate::{
graph::AnimationNodeIndex,
prelude::{Animatable, BlendInput},
AnimationEntityMut, AnimationEvaluationError,
};
use bevy_utils::Hashed;
use downcast_rs::{impl_downcast, Downcast};
/// A value on a component that Bevy can animate.

View File

@ -17,8 +17,8 @@ use bevy_ecs::{
resource::Resource,
system::{Res, ResMut},
};
use bevy_platform_support::collections::HashMap;
use bevy_reflect::{prelude::ReflectDefault, Reflect, ReflectSerialize};
use bevy_utils::HashMap;
use derive_more::derive::From;
use petgraph::{
graph::{DiGraph, NodeIndex},

View File

@ -40,10 +40,11 @@ use bevy_ecs::{
world::EntityMutExcept,
};
use bevy_math::FloatOrd;
use bevy_platform_support::{collections::HashMap, hash::NoOpHash};
use bevy_reflect::{prelude::ReflectDefault, Reflect, TypePath};
use bevy_time::Time;
use bevy_transform::TransformSystem;
use bevy_utils::{HashMap, NoOpHash, PreHashMap, PreHashMapExt, TypeIdMap};
use bevy_utils::{PreHashMap, PreHashMapExt, TypeIdMap};
use petgraph::graph::NodeIndex;
use serde::{Deserialize, Serialize};
use thread_local::ThreadLocal;
@ -754,10 +755,10 @@ impl AnimationCurveEvaluators {
.component_property_curve_evaluators
.get_or_insert_with(component_property, func),
EvaluatorId::Type(type_id) => match self.type_id_curve_evaluators.entry(type_id) {
bevy_utils::hashbrown::hash_map::Entry::Occupied(occupied_entry) => {
bevy_platform_support::collections::hash_map::Entry::Occupied(occupied_entry) => {
&mut **occupied_entry.into_mut()
}
bevy_utils::hashbrown::hash_map::Entry::Vacant(vacant_entry) => {
bevy_platform_support::collections::hash_map::Entry::Vacant(vacant_entry) => {
&mut **vacant_entry.insert(func())
}
},

View File

@ -16,7 +16,7 @@ use bevy_ecs::{
schedule::{ScheduleBuildSettings, ScheduleLabel},
system::{IntoObserverSystem, SystemId, SystemInput},
};
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
use core::{fmt::Debug, num::NonZero, panic::AssertUnwindSafe};
use log::debug;
use thiserror::Error;

View File

@ -4,7 +4,8 @@ use alloc::{
string::{String, ToString},
vec::Vec,
};
use bevy_utils::{hashbrown::hash_map::Entry, TypeIdMap};
use bevy_platform_support::collections::hash_map::Entry;
use bevy_utils::TypeIdMap;
use core::any::TypeId;
use log::{debug, warn};

View File

@ -6,7 +6,7 @@ use bevy_ecs::{
schedule::{InternedScheduleLabel, ScheduleBuildSettings, ScheduleLabel},
system::{SystemId, SystemInput},
};
use bevy_utils::{HashMap, HashSet};
use bevy_platform_support::collections::{HashMap, HashSet};
use core::fmt::Debug;
#[cfg(feature = "trace")]

View File

@ -27,6 +27,9 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
] }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"std",
] }
stackfuture = "0.3"
atomicow = "1.0"

View File

@ -13,7 +13,7 @@ use bevy_ecs::{
storage::{Table, TableRow},
world::unsafe_world_cell::UnsafeWorldCell,
};
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
use core::marker::PhantomData;
use disqualified::ShortName;
use tracing::error;

View File

@ -9,8 +9,8 @@ use bevy_ecs::{
resource::Resource,
system::{Res, ResMut, SystemChangeTick},
};
use bevy_platform_support::collections::HashMap;
use bevy_reflect::{Reflect, TypePath};
use bevy_utils::HashMap;
use core::{any::TypeId, iter::Enumerate, marker::PhantomData, sync::atomic::AtomicU32};
use crossbeam_channel::{Receiver, Sender};
use serde::{Deserialize, Serialize};
@ -595,7 +595,7 @@ impl<A: Asset> Assets<A> {
pub struct AssetsMutIterator<'a, A: Asset> {
queued_events: &'a mut Vec<AssetEvent<A>>,
dense_storage: Enumerate<core::slice::IterMut<'a, Entry<A>>>,
hash_map: bevy_utils::hashbrown::hash_map::IterMut<'a, Uuid, A>,
hash_map: bevy_platform_support::collections::hash_map::IterMut<'a, Uuid, A>,
}
impl<'a, A: Asset> Iterator for AssetsMutIterator<'a, A> {

View File

@ -515,8 +515,8 @@ pub enum UntypedAssetConversionError {
#[cfg(test)]
mod tests {
use alloc::boxed::Box;
use bevy_platform_support::hash::FixedHasher;
use bevy_reflect::PartialReflect;
use bevy_utils::FixedHasher;
use core::hash::BuildHasher;
use super::*;

View File

@ -420,7 +420,7 @@ mod tests {
fn hash<T: Hash>(data: &T) -> u64 {
use core::hash::BuildHasher;
bevy_utils::FixedHasher.hash_one(data)
bevy_platform_support::hash::FixedHasher.hash_one(data)
}
/// Typed and Untyped `AssetIds` should be equivalent to each other and themselves

View File

@ -4,7 +4,7 @@ use crate::io::{
AssetSourceEvent, AssetWatcher,
};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
use core::time::Duration;
use notify_debouncer_full::{notify::RecommendedWatcher, Debouncer, RecommendedCache};
use parking_lot::RwLock;

View File

@ -26,7 +26,9 @@ pub const EMBEDDED: &str = "embedded";
pub struct EmbeddedAssetRegistry {
dir: Dir,
#[cfg(feature = "embedded_watcher")]
root_paths: alloc::sync::Arc<parking_lot::RwLock<bevy_utils::HashMap<Box<Path>, PathBuf>>>,
root_paths: alloc::sync::Arc<
parking_lot::RwLock<bevy_platform_support::collections::HashMap<Box<Path>, PathBuf>>,
>,
}
impl EmbeddedAssetRegistry {

View File

@ -1,6 +1,6 @@
use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
use alloc::{boxed::Box, sync::Arc};
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
use crossbeam_channel::{Receiver, Sender};
use parking_lot::RwLock;
use std::path::Path;

View File

@ -1,6 +1,6 @@
use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
use alloc::{borrow::ToOwned, boxed::Box, sync::Arc, vec::Vec};
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
use core::{pin::Pin, task::Poll};
use futures_io::AsyncRead;
use futures_lite::{ready, Stream};

View File

@ -9,7 +9,7 @@ use alloc::{
};
use atomicow::CowArc;
use bevy_ecs::resource::Resource;
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
use core::{fmt::Display, hash::Hash, time::Duration};
use thiserror::Error;
use tracing::{error, warn};

View File

@ -219,8 +219,8 @@ use bevy_ecs::{
schedule::{IntoSystemConfigs, IntoSystemSetConfigs, SystemSet},
world::FromWorld,
};
use bevy_platform_support::collections::HashSet;
use bevy_reflect::{FromReflect, GetTypeRegistration, Reflect, TypePath};
use bevy_utils::HashSet;
use core::any::TypeId;
use tracing::error;
@ -653,8 +653,8 @@ mod tests {
schedule::{LogLevel, ScheduleBuildSettings},
};
use bevy_log::LogPlugin;
use bevy_platform_support::collections::HashMap;
use bevy_reflect::TypePath;
use bevy_utils::HashMap;
use core::time::Duration;
use serde::{Deserialize, Serialize};
use std::path::Path;

View File

@ -13,8 +13,8 @@ use alloc::{
};
use atomicow::CowArc;
use bevy_ecs::world::World;
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
use bevy_utils::{HashMap, HashSet};
use core::any::{Any, TypeId};
use downcast_rs::{impl_downcast, Downcast};
use ron::error::SpannedError;

View File

@ -5,7 +5,7 @@ use alloc::{
vec::Vec,
};
use async_fs::File;
use bevy_utils::HashSet;
use bevy_platform_support::collections::HashSet;
use futures_lite::{AsyncReadExt, AsyncWriteExt};
use std::path::PathBuf;
use thiserror::Error;

View File

@ -58,8 +58,8 @@ use crate::{
};
use alloc::{borrow::ToOwned, boxed::Box, collections::VecDeque, sync::Arc, vec, vec::Vec};
use bevy_ecs::prelude::*;
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_tasks::IoTaskPool;
use bevy_utils::{HashMap, HashSet};
use futures_io::ErrorKind;
use futures_lite::{AsyncReadExt, AsyncWriteExt, StreamExt};
use parking_lot::RwLock;

View File

@ -4,8 +4,8 @@ use crate::{
};
use alloc::boxed::Box;
use atomicow::CowArc;
use bevy_platform_support::collections::HashMap;
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
use bevy_utils::HashMap;
use core::{borrow::Borrow, hash::Hash, ops::Deref};
use serde::{Deserialize, Serialize};

View File

@ -11,8 +11,9 @@ use alloc::{
vec::Vec,
};
use bevy_ecs::world::World;
use bevy_platform_support::collections::{hash_map::Entry, HashMap, HashSet};
use bevy_tasks::Task;
use bevy_utils::{Entry, HashMap, HashSet, TypeIdMap};
use bevy_utils::TypeIdMap;
use core::{any::TypeId, task::Waker};
use crossbeam_channel::Sender;
use either::Either;

View File

@ -4,8 +4,9 @@ use crate::{
};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use async_broadcast::RecvError;
use bevy_platform_support::collections::HashMap;
use bevy_tasks::IoTaskPool;
use bevy_utils::{HashMap, TypeIdMap};
use bevy_utils::TypeIdMap;
use core::any::TypeId;
use thiserror::Error;
use tracing::warn;

View File

@ -25,8 +25,8 @@ use alloc::{
};
use atomicow::CowArc;
use bevy_ecs::prelude::*;
use bevy_platform_support::collections::HashSet;
use bevy_tasks::IoTaskPool;
use bevy_utils::HashSet;
use core::{any::TypeId, future::Future, panic::AssertUnwindSafe, task::Poll};
use crossbeam_channel::{Receiver, Sender};
use either::Either;

View File

@ -1,8 +1,8 @@
use crate::{meta::Settings, Asset, ErasedLoadedAsset, Handle, LabeledAsset, UntypedHandle};
use alloc::boxed::Box;
use atomicow::CowArc;
use bevy_platform_support::collections::HashMap;
use bevy_tasks::ConditionalSendFuture;
use bevy_utils::HashMap;
use core::{
borrow::Borrow,
convert::Infallible,

View File

@ -37,6 +37,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_window = { path = "../bevy_window", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"std",
"serialize",
] }
serde = { version = "1", features = ["derive"] }

View File

@ -1,11 +1,11 @@
use bevy_ecs::prelude::*;
use bevy_platform_support::collections::{hash_map::Entry, HashMap};
use bevy_render::{
render_resource::{StorageBuffer, UniformBuffer},
renderer::{RenderDevice, RenderQueue},
sync_world::RenderEntity,
Extract,
};
use bevy_utils::{Entry, HashMap};
use super::{pipeline::AutoExposureUniform, AutoExposure};

View File

@ -33,12 +33,12 @@ pub mod graph {
use core::ops::Range;
use bevy_asset::UntypedAssetId;
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_render::{
batching::gpu_preprocessing::GpuPreprocessingMode,
render_phase::PhaseItemBatchSetKey,
view::{ExtractedView, RetainedViewEntity},
};
use bevy_utils::{HashMap, HashSet};
pub use camera_2d::*;
pub use main_opaque_pass_2d_node::*;
pub use main_transparent_pass_2d_node::*;

View File

@ -81,6 +81,7 @@ use bevy_color::LinearRgba;
use bevy_ecs::prelude::*;
use bevy_image::BevyDefault;
use bevy_math::FloatOrd;
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_render::{
camera::{Camera, ExtractedCamera},
extract_component::ExtractComponentPlugin,
@ -101,7 +102,6 @@ use bevy_render::{
view::{ExtractedView, ViewDepthTexture, ViewTarget},
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_utils::{HashMap, HashSet};
use nonmax::NonMaxU32;
use tracing::warn;

View File

@ -4,6 +4,7 @@ use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, Handle};
use bevy_ecs::{component::*, prelude::*};
use bevy_math::UVec2;
use bevy_platform_support::collections::HashSet;
use bevy_platform_support::time::Instant;
use bevy_reflect::Reflect;
use bevy_render::{
@ -17,7 +18,6 @@ use bevy_render::{
view::Msaa,
Render, RenderApp, RenderSet,
};
use bevy_utils::HashSet;
use bevy_window::PrimaryWindow;
use resolve::{
node::{OitResolveNode, OitResolvePass},

View File

@ -1,13 +1,13 @@
use crate::blit::{BlitPipeline, BlitPipelineKey};
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use bevy_platform_support::collections::HashSet;
use bevy_render::{
camera::{CameraOutputMode, ExtractedCamera},
render_resource::*,
view::ViewTarget,
Render, RenderApp, RenderSet,
};
use bevy_utils::HashSet;
mod node;

View File

@ -19,6 +19,7 @@ serialize = [
"bevy_ecs/serialize",
"bevy_time/serialize",
"bevy_utils/serde",
"bevy_platform_support/serialize",
]
## Disables diagnostics that are unsupported when Bevy is dynamically linked

View File

@ -7,8 +7,7 @@ use core::{
use bevy_app::{App, SubApp};
use bevy_ecs::resource::Resource;
use bevy_ecs::system::{Deferred, Res, SystemBuffer, SystemParam};
use bevy_platform_support::time::Instant;
use bevy_utils::{HashMap, PassHash};
use bevy_platform_support::{collections::HashMap, hash::PassHash, time::Instant};
use const_fnv1a_hash::fnv1a_hash_str_64;
use crate::DEFAULT_MAX_HISTORY_LENGTH;

View File

@ -20,7 +20,7 @@ default = ["std", "bevy_reflect", "async_executor"]
multi_threaded = ["bevy_tasks/multi_threaded", "dep:arrayvec"]
## Adds serialization support through `serde`.
serialize = ["dep:serde", "bevy_utils/serde"]
serialize = ["dep:serde", "bevy_utils/serde", "bevy_platform_support/serialize"]
## Adds runtime reflection support using `bevy_reflect`.
bevy_reflect = ["dep:bevy_reflect"]

View File

@ -27,7 +27,7 @@ use crate::{
storage::{ImmutableSparseSet, SparseArray, SparseSet, SparseSetIndex, TableId, TableRow},
};
use alloc::{boxed::Box, vec::Vec};
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
use core::{
hash::Hash,
ops::{Index, IndexMut, RangeFrom},

View File

@ -21,8 +21,9 @@ use crate::{
world::{unsafe_world_cell::UnsafeWorldCell, ON_ADD, ON_INSERT, ON_REPLACE},
};
use alloc::{boxed::Box, vec, vec::Vec};
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_ptr::{ConstNonNull, OwningPtr};
use bevy_utils::{HashMap, HashSet, TypeIdMap};
use bevy_utils::TypeIdMap;
#[cfg(feature = "track_location")]
use core::panic::Location;
use core::{any::TypeId, ptr::NonNull};

View File

@ -16,11 +16,12 @@ use crate::{
use alloc::boxed::Box;
use alloc::{borrow::Cow, format, vec::Vec};
pub use bevy_ecs_macros::Component;
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_platform_support::sync::Arc;
use bevy_ptr::{OwningPtr, UnsafeCellDeref};
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
use bevy_utils::{HashMap, HashSet, TypeIdMap};
use bevy_utils::TypeIdMap;
use core::{
alloc::Layout,
any::{Any, TypeId},
@ -531,7 +532,7 @@ pub struct HookContext {
///
/// ```
/// use bevy_ecs::prelude::*;
/// use bevy_utils::HashSet;
/// use bevy_platform_support::collections::HashSet;
///
/// #[derive(Component)]
/// struct MyTrackedComponent;

View File

@ -1,7 +1,7 @@
use alloc::{borrow::ToOwned, vec::Vec};
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_platform_support::sync::Arc;
use bevy_ptr::{Ptr, PtrMut};
use bevy_utils::{HashMap, HashSet};
use bumpalo::Bump;
use core::{any::TypeId, ptr::NonNull};

View File

@ -25,7 +25,7 @@ impl BuildHasher for EntityHash {
///
/// If you have an unusual case -- say all your indices are multiples of 256
/// or most of the entities are dead generations -- then you might want also to
/// try [`DefaultHasher`](bevy_utils::DefaultHasher) for a slower hash
/// try [`DefaultHasher`](bevy_platform_support::hash::DefaultHasher) for a slower hash
/// computation but fewer lookup conflicts.
#[derive(Debug, Default)]
pub struct EntityHasher {

View File

@ -1,6 +1,6 @@
//! Contains the [`EntityHashMap`] type, a [`HashMap`] pre-configured to use [`EntityHash`] hashing.
//!
//! This module is a lightweight wrapper around [`hashbrown`](bevy_utils::hashbrown)'s [`HashMap`] that is more performant for [`Entity`] keys.
//! This module is a lightweight wrapper around Bevy's [`HashMap`] that is more performant for [`Entity`] keys.
use core::{
fmt::{self, Debug, Formatter},
@ -9,9 +9,9 @@ use core::{
ops::{Deref, DerefMut, Index},
};
use bevy_platform_support::collections::hash_map::{self, HashMap};
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
use bevy_utils::hashbrown::hash_map::{self, HashMap};
use super::{Entity, EntityHash, EntitySetIterator, TrustedEntityBorrow};

View File

@ -1,6 +1,6 @@
//! Contains the [`EntityHashSet`] type, a [`HashSet`] pre-configured to use [`EntityHash`] hashing.
//!
//! This module is a lightweight wrapper around [`hashbrown`](bevy_utils::hashbrown)'s [`HashSet`] that is more performant for [`Entity`] keys.
//! This module is a lightweight wrapper around Bevy's [`HashSet`] that is more performant for [`Entity`] keys.
use core::{
fmt::{self, Debug, Formatter},
@ -12,9 +12,9 @@ use core::{
},
};
use bevy_platform_support::collections::hash_set::{self, HashSet};
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
use bevy_utils::hashbrown::hash_set::{self, HashSet};
use super::{Entity, EntityHash, EntitySetIterator};

View File

@ -23,7 +23,7 @@ use super::{hash_map::EntityHashMap, VisitEntitiesMut};
/// Implementing this trait correctly is required for properly loading components
/// with entity references from scenes.
///
/// [`HashSet<Entity>`]: bevy_utils::HashSet
/// [`HashSet<Entity>`]: bevy_platform_support::collections::HashSet
///
/// ## Example
///

View File

@ -62,7 +62,7 @@ mod tests {
world::World,
};
use alloc::{string::String, vec, vec::Vec};
use bevy_utils::HashSet;
use bevy_platform_support::collections::HashSet;
use super::*;

View File

@ -5,11 +5,13 @@
//! and make comparisons for any type as fast as integers.
use alloc::{borrow::ToOwned, boxed::Box};
use bevy_platform_support::{
collections::HashSet,
hash::FixedHasher,
sync::{PoisonError, RwLock},
};
use core::{fmt::Debug, hash::Hash, ops::Deref};
use bevy_platform_support::sync::{PoisonError, RwLock};
use bevy_utils::{FixedHasher, HashSet};
/// An interned value. Will stay valid until the end of the program and will not drop.
///
/// For details on interning, see [the module level docs](self).
@ -168,7 +170,7 @@ impl<T: ?Sized> Default for Interner<T> {
#[cfg(test)]
mod tests {
use alloc::{boxed::Box, string::ToString};
use bevy_utils::FixedHasher;
use bevy_platform_support::hash::FixedHasher;
use core::hash::{BuildHasher, Hash, Hasher};
use crate::intern::{Internable, Interned, Interner};

View File

@ -146,8 +146,8 @@ mod tests {
vec::Vec,
};
use bevy_ecs_macros::{VisitEntities, VisitEntitiesMut};
use bevy_platform_support::collections::HashSet;
use bevy_tasks::{ComputeTaskPool, TaskPool};
use bevy_utils::HashSet;
use core::{
any::TypeId,
marker::PhantomData,

View File

@ -6,7 +6,7 @@ use alloc::{
borrow::{Cow, ToOwned},
string::String,
};
use bevy_utils::FixedHasher;
use bevy_platform_support::hash::FixedHasher;
use core::{
hash::{BuildHasher, Hash, Hasher},
ops::Deref,

View File

@ -15,8 +15,8 @@ use crate::{
world::{DeferredWorld, *},
};
use alloc::vec::Vec;
use bevy_platform_support::collections::HashMap;
use bevy_ptr::Ptr;
use bevy_utils::HashMap;
use core::{
fmt::Debug,
marker::PhantomData,
@ -846,8 +846,8 @@ mod tests {
#[cfg(feature = "track_location")]
use core::panic::Location;
use bevy_platform_support::collections::HashMap;
use bevy_ptr::OwningPtr;
use bevy_utils::HashMap;
use crate as bevy_ecs;
use crate::component::ComponentId;

View File

@ -5,7 +5,7 @@
//! [`petgraph`]: https://docs.rs/petgraph/0.6.5/petgraph/
use alloc::vec::Vec;
use bevy_utils::{hashbrown::HashSet, FixedHasher};
use bevy_platform_support::{collections::HashSet, hash::FixedHasher};
use core::{
fmt,
hash::{BuildHasher, Hash},

View File

@ -2,7 +2,7 @@ use alloc::{vec, vec::Vec};
use core::fmt::Debug;
use smallvec::SmallVec;
use bevy_utils::{HashMap, HashSet};
use bevy_platform_support::collections::{HashMap, HashSet};
use fixedbitset::FixedBitSet;
use crate::schedule::set::*;

View File

@ -10,7 +10,8 @@ use alloc::{
vec,
vec::Vec,
};
use bevy_utils::{default, HashMap, HashSet};
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_utils::default;
use core::fmt::{Debug, Write};
use disqualified::ShortName;
use fixedbitset::FixedBitSet;

View File

@ -4,7 +4,8 @@ use crate::{
system::{IntoSystem, ResMut},
};
use alloc::vec::Vec;
use bevy_utils::{HashMap, TypeIdMap};
use bevy_platform_support::collections::HashMap;
use bevy_utils::TypeIdMap;
use core::any::TypeId;
use fixedbitset::FixedBitSet;
use log::{info, warn};

View File

@ -6,8 +6,8 @@ use crate::{
storage::{blob_vec::BlobVec, ImmutableSparseSet, SparseSet},
};
use alloc::{boxed::Box, vec, vec::Vec};
use bevy_platform_support::collections::HashMap;
use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref};
use bevy_utils::HashMap;
pub use column::*;
#[cfg(feature = "track_location")]
use core::panic::Location;

View File

@ -19,8 +19,8 @@ use crate::{
},
};
use alloc::vec::Vec;
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_ptr::{OwningPtr, Ptr};
use bevy_utils::{HashMap, HashSet};
#[cfg(feature = "track_location")]
use core::panic::Location;
use core::{
@ -244,7 +244,7 @@ impl<'w> EntityRef<'w> {
/// ## [`HashSet`] of [`ComponentId`]s
///
/// ```
/// # use bevy_utils::HashSet;
/// # use bevy_platform_support::collections::HashSet;
/// # use bevy_ecs::{prelude::*, component::ComponentId};
/// #
/// # #[derive(Component, PartialEq, Debug)]
@ -787,7 +787,7 @@ impl<'w> EntityMut<'w> {
/// ## [`HashSet`] of [`ComponentId`]s
///
/// ```
/// # use bevy_utils::HashSet;
/// # use bevy_platform_support::collections::HashSet;
/// # use bevy_ecs::{prelude::*, component::ComponentId};
/// #
/// # #[derive(Component, PartialEq, Debug)]

View File

@ -3778,7 +3778,7 @@ mod tests {
vec::Vec,
};
use bevy_ecs_macros::Component;
use bevy_utils::{HashMap, HashSet};
use bevy_platform_support::collections::{HashMap, HashSet};
use core::{
any::TypeId,
panic,

View File

@ -15,6 +15,9 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" }
bevy_input = { path = "../bevy_input", version = "0.16.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_time = { path = "../bevy_time", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"std",
] }
# other
gilrs = "0.11.0"

View File

@ -18,7 +18,8 @@ use bevy_app::{App, Plugin, PostUpdate, PreStartup, PreUpdate};
use bevy_ecs::entity::hash_map::EntityHashMap;
use bevy_ecs::prelude::*;
use bevy_input::InputSystem;
use bevy_utils::{synccell::SyncCell, HashMap};
use bevy_platform_support::collections::HashMap;
use bevy_utils::synccell::SyncCell;
use gilrs::GilrsBuilder;
use gilrs_system::{gilrs_event_startup_system, gilrs_event_system};
use rumble::{play_gilrs_rumble, RunningRumbleEffects};

View File

@ -4,8 +4,9 @@ use bevy_ecs::prelude::{EventReader, Res, ResMut, Resource};
#[cfg(target_arch = "wasm32")]
use bevy_ecs::system::NonSendMut;
use bevy_input::gamepad::{GamepadRumbleIntensity, GamepadRumbleRequest};
use bevy_platform_support::collections::HashMap;
use bevy_time::{Real, Time};
use bevy_utils::{synccell::SyncCell, HashMap};
use bevy_utils::synccell::SyncCell;
use core::time::Duration;
use gilrs::{
ff::{self, BaseEffect, BaseEffectType, Repeat, Replay},

View File

@ -37,6 +37,10 @@ bevy_scene = { path = "../bevy_scene", version = "0.16.0-dev", features = [
bevy_transform = { path = "../bevy_transform", version = "0.16.0-dev" }
bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"std",
"serialize",
] }
# other
gltf = { version = "1.4.0", default-features = false, features = [

View File

@ -94,7 +94,7 @@ extern crate alloc;
#[cfg(feature = "bevy_animation")]
use bevy_animation::AnimationClip;
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
mod loader;
mod vertex_attributes;

View File

@ -24,6 +24,7 @@ use bevy_pbr::{
DirectionalLight, MeshMaterial3d, PointLight, SpotLight, StandardMaterial, UvChannel,
MAX_JOINTS,
};
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_render::{
alpha::AlphaMode,
camera::{Camera, OrthographicProjection, PerspectiveProjection, Projection, ScalingMode},
@ -41,7 +42,6 @@ use bevy_scene::Scene;
#[cfg(not(target_arch = "wasm32"))]
use bevy_tasks::IoTaskPool;
use bevy_transform::components::Transform;
use bevy_utils::{HashMap, HashSet};
use gltf::{
accessor::Iter,
image::Source,

View File

@ -1,9 +1,9 @@
use bevy_platform_support::collections::HashMap;
use bevy_render::{
mesh::{MeshVertexAttribute, VertexAttributeValues as Values},
prelude::Mesh,
render_resource::VertexFormat,
};
use bevy_utils::HashMap;
use gltf::{
accessor::{DataType, Dimensions},
mesh::util::{ReadColors, ReadJoints, ReadTexCoords, ReadWeights},

View File

@ -30,7 +30,11 @@ qoi = ["image/qoi"]
tga = ["image/tga"]
tiff = ["image/tiff"]
webp = ["image/webp"]
serialize = ["bevy_reflect"]
serialize = [
"bevy_reflect",
"bevy_platform_support/serialize",
"bevy_utils/serde",
]
# For ktx2 supercompression
zlib = ["flate2"]
@ -49,6 +53,9 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
"bevy",
], optional = true }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"std",
] }
# rendering
image = { version = "0.25.2", default-features = false }

View File

@ -1,11 +1,11 @@
use bevy_app::prelude::*;
use bevy_asset::{Asset, AssetApp as _, AssetId, Assets, Handle};
use bevy_math::{URect, UVec2};
use bevy_platform_support::collections::HashMap;
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
#[cfg(feature = "serialize")]
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
use bevy_utils::HashMap;
use crate::Image;

View File

@ -1,6 +1,6 @@
use bevy_asset::{AssetId, RenderAssetUsages};
use bevy_math::{URect, UVec2};
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
use rectangle_pack::{
contains_smallest_box, pack_rects, volume_heuristic, GroupedRectsToPlace, PackedLocation,
RectToInsert, TargetBin,

View File

@ -27,6 +27,7 @@ serialize = [
"smol_str/serde",
"bevy_ecs/serialize",
"bevy_math/serialize",
"bevy_platform_support/serialize",
]
## Uses the small-string optimization provided by `smol_str`.
@ -43,6 +44,7 @@ std = [
"bevy_math/std",
"bevy_utils/std",
"bevy_reflect/std",
"bevy_platform_support/std",
]
## `critical-section` provides the building blocks for synchronization primitives
@ -51,6 +53,7 @@ critical-section = [
"bevy_app/critical-section",
"bevy_ecs/critical-section",
"bevy_reflect?/critical-section",
"bevy_platform_support/critical-section",
]
## `portable-atomic` provides additional platform support for atomic types and
@ -59,6 +62,7 @@ portable-atomic = [
"bevy_app/portable-atomic",
"bevy_ecs/portable-atomic",
"bevy_reflect?/portable-atomic",
"bevy_platform_support/portable-atomic",
]
## Uses the `libm` maths library instead of the one provided in `std` and `core`.
@ -73,6 +77,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
"glam",
], default-features = false, optional = true }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false }
# other
serde = { version = "1", features = [

View File

@ -1,7 +1,7 @@
//! The generic axis type.
use bevy_ecs::resource::Resource;
use bevy_utils::HashMap;
use bevy_platform_support::collections::HashMap;
use core::hash::Hash;
#[cfg(feature = "bevy_reflect")]

View File

@ -1,7 +1,7 @@
//! The generic input type.
use bevy_ecs::resource::Resource;
use bevy_utils::HashSet;
use bevy_platform_support::collections::HashSet;
use core::hash::Hash;
#[cfg(feature = "bevy_reflect")]
use {

View File

@ -17,11 +17,11 @@ use bevy_ecs::{
};
use bevy_math::ops;
use bevy_math::Vec2;
use bevy_platform_support::collections::HashMap;
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
#[cfg(all(feature = "serialize", feature = "bevy_reflect"))]
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
use bevy_utils::HashMap;
use derive_more::derive::From;
use log::{info, warn};
use thiserror::Error;

View File

@ -7,9 +7,9 @@ use bevy_ecs::{
system::ResMut,
};
use bevy_math::Vec2;
use bevy_platform_support::collections::HashMap;
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
use bevy_utils::HashMap;
#[cfg(all(feature = "serialize", feature = "bevy_reflect"))]
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};

View File

@ -97,6 +97,7 @@ serialize = [
"bevy_ui?/serialize",
"bevy_window?/serialize",
"bevy_winit?/serialize",
"bevy_platform_support/serialize",
]
multi_threaded = [
"bevy_asset?/multi_threaded",

View File

@ -21,6 +21,10 @@ bevy_transform = { path = "../bevy_transform", version = "0.16.0-dev" }
bevy_mikktspace = { path = "../bevy_mikktspace", version = "0.16.0-dev" }
bevy_derive = { path = "../bevy_derive", version = "0.16.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"std",
"serialize",
] }
# other
bitflags = { version = "2.3", features = ["serde"] }

View File

@ -1128,7 +1128,7 @@ impl From<Capsule2d> for Mesh {
#[cfg(test)]
mod tests {
use bevy_math::{prelude::Annulus, primitives::RegularPolygon, FloatOrd};
use bevy_utils::HashSet;
use bevy_platform_support::collections::HashSet;
use crate::{Mesh, MeshBuilder, Meshable, VertexAttributeValues};

View File

@ -2,7 +2,7 @@ use alloc::sync::Arc;
use bevy_derive::EnumVariantMeta;
use bevy_ecs::resource::Resource;
use bevy_math::Vec3;
use bevy_utils::HashSet;
use bevy_platform_support::collections::HashSet;
use bytemuck::cast_slice;
use core::hash::{Hash, Hasher};
use thiserror::Error;

View File

@ -47,6 +47,9 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.16.0-dev", optional = true }
bevy_transform = { path = "../bevy_transform", version = "0.16.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_window = { path = "../bevy_window", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"std",
] }
# other
bitflags = "2.3"

View File

@ -13,6 +13,7 @@ use bevy_ecs::{
world::{FromWorld, World},
};
use bevy_math::{uvec4, AspectRatio, UVec2, UVec3, UVec4, Vec3Swizzles as _, Vec4};
use bevy_platform_support::collections::HashSet;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
camera::Camera,
@ -24,7 +25,6 @@ use bevy_render::{
sync_world::RenderEntity,
Extract,
};
use bevy_utils::HashSet;
use tracing::warn;
pub(crate) use crate::cluster::assign::assign_objects_to_clusters;

View File

@ -15,6 +15,7 @@ use bevy_ecs::{
};
use bevy_image::Image;
use bevy_math::{Affine3A, FloatOrd, Mat4, Vec3A, Vec4};
use bevy_platform_support::collections::HashMap;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
extract_instances::ExtractInstancesPlugin,
@ -29,7 +30,6 @@ use bevy_render::{
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_transform::{components::Transform, prelude::GlobalTransform};
use bevy_utils::HashMap;
use tracing::error;
use core::{hash::Hash, ops::Deref};

View File

@ -47,6 +47,7 @@ use bevy_ecs::{
};
use bevy_image::Image;
use bevy_math::{uvec2, vec4, Rect, UVec2};
use bevy_platform_support::collections::HashSet;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
render_asset::RenderAssets,
@ -58,7 +59,7 @@ use bevy_render::{
Extract, ExtractSchedule, RenderApp,
};
use bevy_render::{renderer::RenderDevice, sync_world::MainEntityHashMap};
use bevy_utils::{default, HashSet};
use bevy_utils::default;
use fixedbitset::FixedBitSet;
use nonmax::{NonMaxU16, NonMaxU32};
use tracing::error;

View File

@ -27,6 +27,7 @@ use bevy_ecs::{
SystemParamItem,
},
};
use bevy_platform_support::collections::HashMap;
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;
use bevy_render::{
@ -44,7 +45,6 @@ use bevy_render::{
};
use bevy_render::{mesh::allocator::MeshAllocator, sync_world::MainEntityHashMap};
use bevy_render::{texture::FallbackImage, view::RenderVisibleEntities};
use bevy_utils::HashMap;
use core::{hash::Hash, marker::PhantomData};
use tracing::error;

View File

@ -10,6 +10,7 @@ use bevy_ecs::{
resource::Resource,
world::{FromWorld, World},
};
use bevy_platform_support::collections::HashMap;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
render_resource::{
@ -21,7 +22,7 @@ use bevy_render::{
renderer::RenderDevice,
texture::FallbackImage,
};
use bevy_utils::{default, HashMap};
use bevy_utils::default;
use core::{any, iter, marker::PhantomData, num::NonZero};
use tracing::error;

View File

@ -3,11 +3,11 @@ use super::asset::{
};
use alloc::borrow::Cow;
use bevy_math::{ops::log2, IVec3, Vec2, Vec3, Vec3Swizzles};
use bevy_platform_support::collections::HashMap;
use bevy_render::{
mesh::{Indices, Mesh},
render_resource::PrimitiveTopology,
};
use bevy_utils::HashMap;
use bitvec::{order::Lsb0, vec::BitVec, view::BitView};
use core::{iter, ops::Range};
use half::f16;

View File

@ -12,11 +12,11 @@ use bevy_ecs::{
resource::Resource,
system::{Local, Query, Res, ResMut, SystemState},
};
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_render::{
render_resource::StorageBuffer, sync_world::MainEntity, view::RenderLayers, MainWorld,
};
use bevy_transform::components::GlobalTransform;
use bevy_utils::{HashMap, HashSet};
use core::ops::{DerefMut, Range};
/// Manages data for each entity with a [`MeshletMesh`].

View File

@ -13,6 +13,7 @@ use bevy_core_pipeline::{
tonemapping::{DebandDither, Tonemapping},
};
use bevy_derive::{Deref, DerefMut};
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_render::{
camera::TemporalJitter,
mesh::{Mesh, MeshVertexBufferLayout, MeshVertexBufferLayoutRef, MeshVertexBufferLayouts},
@ -20,7 +21,6 @@ use bevy_render::{
render_resource::*,
view::ExtractedView,
};
use bevy_utils::{HashMap, HashSet};
use core::hash::Hash;
/// A list of `(Material ID, Pipeline, BindGroup)` for a view for use in [`super::MeshletMainOpaquePass3dNode`].

View File

@ -11,11 +11,11 @@ use bevy_ecs::{
world::{FromWorld, World},
};
use bevy_math::Vec2;
use bevy_platform_support::collections::HashMap;
use bevy_render::{
render_resource::BufferAddress,
renderer::{RenderDevice, RenderQueue},
};
use bevy_utils::HashMap;
use core::ops::Range;
/// Manages uploading [`MeshletMesh`] asset data to the GPU.

View File

@ -11,6 +11,7 @@ use bevy_ecs::{
system::lifetimeless::Read,
};
use bevy_math::{ops, Mat4, UVec4, Vec2, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles};
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_render::{
batching::gpu_preprocessing::{GpuPreprocessingMode, GpuPreprocessingSupport},
camera::SortedCameras,
@ -35,7 +36,7 @@ use bevy_render::{
sync_world::{MainEntity, RenderEntity},
};
use bevy_transform::{components::GlobalTransform, prelude::Transform};
use bevy_utils::{default, HashMap, HashSet};
use bevy_utils::default;
use core::{hash::Hash, ops::Range};
#[cfg(feature = "trace")]
use tracing::info_span;

View File

@ -17,6 +17,7 @@ use bevy_ecs::{
};
use bevy_image::{BevyDefault, ImageSampler, TextureFormatPixelInfo};
use bevy_math::{Affine3, Rect, UVec2, Vec3, Vec4};
use bevy_platform_support::collections::{hash_map::Entry, HashMap};
use bevy_render::{
batching::{
gpu_preprocessing::{
@ -44,7 +45,7 @@ use bevy_render::{
Extract,
};
use bevy_transform::components::GlobalTransform;
use bevy_utils::{default, hashbrown::hash_map::Entry, HashMap, Parallel};
use bevy_utils::{default, Parallel};
use material_bind_groups::MaterialBindingId;
use render::skin::{self, SkinIndex};
use tracing::{error, warn};

View File

@ -129,10 +129,10 @@ pub mod ray {
use crate::backend::prelude::{PointerId, PointerLocation};
use bevy_ecs::prelude::*;
use bevy_math::Ray3d;
use bevy_platform_support::collections::{hash_map::Iter, HashMap};
use bevy_reflect::Reflect;
use bevy_render::camera::Camera;
use bevy_transform::prelude::GlobalTransform;
use bevy_utils::{hashbrown::hash_map::Iter, HashMap};
use bevy_window::PrimaryWindow;
/// Identifies a ray constructed from some (pointer, camera) combination. A pointer can be over

View File

@ -41,10 +41,10 @@ use core::{fmt::Debug, time::Duration};
use bevy_ecs::{prelude::*, query::QueryData, system::SystemParam, traversal::Traversal};
use bevy_math::Vec2;
use bevy_platform_support::collections::HashMap;
use bevy_platform_support::time::Instant;
use bevy_reflect::prelude::*;
use bevy_render::camera::NormalizedRenderTarget;
use bevy_utils::HashMap;
use bevy_window::Window;
use tracing::debug;

View File

@ -16,8 +16,8 @@ use crate::{
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*;
use bevy_math::FloatOrd;
use bevy_platform_support::collections::HashMap;
use bevy_reflect::prelude::*;
use bevy_utils::HashMap;
type DepthSortedHits = Vec<(Entity, HitData)>;

View File

@ -19,9 +19,9 @@ use bevy_input::{
ButtonState,
};
use bevy_math::Vec2;
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_reflect::prelude::*;
use bevy_render::camera::RenderTarget;
use bevy_utils::{HashMap, HashSet};
use bevy_window::{PrimaryWindow, WindowEvent, WindowRef};
use tracing::debug;

View File

@ -10,9 +10,9 @@
use bevy_ecs::prelude::*;
use bevy_math::Vec2;
use bevy_platform_support::collections::HashMap;
use bevy_reflect::prelude::*;
use bevy_render::camera::{Camera, NormalizedRenderTarget};
use bevy_utils::HashMap;
use bevy_window::PrimaryWindow;
use uuid::Uuid;

View File

@ -11,6 +11,11 @@ keywords = ["bevy"]
[features]
default = ["std"]
# Functionality
## Adds serialization support through `serde`.
serialize = ["hashbrown/serde"]
# Platform Compatibility
## Allows access to the `std` crate. Enabling this feature will prevent compilation
@ -22,9 +27,10 @@ std = [
"portable-atomic?/std",
"portable-atomic-util?/std",
"spin/std",
"foldhash/std",
]
alloc = ["portable-atomic-util?/alloc"]
alloc = ["portable-atomic-util?/alloc", "dep:hashbrown"]
## `critical-section` provides the building blocks for synchronization primitives
## on all platforms, including `no_std`.
@ -52,6 +58,11 @@ spin = { version = "0.9.8", default-features = false, features = [
"lazy",
"barrier",
] }
foldhash = { version = "0.1.3", default-features = false }
hashbrown = { version = "0.15.1", features = [
"equivalent",
"raw-entry",
], optional = true, default-features = false }
[target.'cfg(target_arch = "wasm32")'.dependencies]
web-time = { version = "1.1", default-features = false }

View File

@ -0,0 +1,64 @@
//! Provides [`HashMap`] and [`HashSet`] from [`hashbrown`] with some customized defaults.\
//!
//! Also provides the [`HashTable`] type, which is specific to [`hashbrown`].
pub use hash_map::HashMap;
pub use hash_set::HashSet;
pub use hash_table::HashTable;
pub use hashbrown::Equivalent;
pub mod hash_map {
//! Provides [`HashMap`]
use crate::hash::FixedHasher;
use hashbrown::hash_map as hb;
// Re-exports to match `std::collections::hash_map`
pub use {
crate::hash::{DefaultHasher, RandomState},
hb::{
Drain, IntoIter, IntoKeys, IntoValues, Iter, IterMut, Keys, OccupiedEntry, VacantEntry,
Values, ValuesMut,
},
};
// Additional items from `hashbrown`
pub use hb::{
EntryRef, ExtractIf, OccupiedError, RawEntryBuilder, RawEntryBuilderMut, RawEntryMut,
RawOccupiedEntryMut,
};
/// Shortcut for [`HashMap`](hb::HashMap) with [`FixedHasher`] as the default hashing provider.
pub type HashMap<K, V, S = FixedHasher> = hb::HashMap<K, V, S>;
/// Shortcut for [`Entry`](hb::Entry) with [`FixedHasher`] as the default hashing provider.
pub type Entry<'a, K, V, S = FixedHasher> = hb::Entry<'a, K, V, S>;
}
pub mod hash_set {
//! Provides [`HashSet`]
use crate::hash::FixedHasher;
use hashbrown::hash_set as hb;
// Re-exports to match `std::collections::hash_set`
pub use hb::{Difference, Drain, Intersection, IntoIter, Iter, SymmetricDifference, Union};
// Additional items from `hashbrown`
pub use hb::{ExtractIf, OccupiedEntry, VacantEntry};
/// Shortcut for [`HashSet`](hb::HashSet) with [`FixedHasher`] as the default hashing provider.
pub type HashSet<T, S = FixedHasher> = hb::HashSet<T, S>;
/// Shortcut for [`Entry`](hb::Entry) with [`FixedHasher`] as the default hashing provider.
pub type Entry<'a, T, S = FixedHasher> = hb::Entry<'a, T, S>;
}
pub mod hash_table {
//! Provides [`HashTable`]
pub use hashbrown::hash_table::{
AbsentEntry, Drain, Entry, ExtractIf, HashTable, IntoIter, Iter, IterHash, IterHashMut,
IterMut, OccupiedEntry, VacantEntry,
};
}

View File

@ -0,0 +1,180 @@
//! Provides replacements for `std::hash` items using [`foldhash`].
//!
//! Also provides some additional items beyond the standard library.
use core::{
fmt::Debug,
hash::{BuildHasher, Hash, Hasher},
marker::PhantomData,
ops::Deref,
};
pub use foldhash::fast::{FixedState, FoldHasher as DefaultHasher, RandomState};
/// For when you want a deterministic hasher.
///
/// Seed was randomly generated with a fair dice roll. Guaranteed to be random:
/// <https://github.com/bevyengine/bevy/pull/1268/files#r560918426>
const FIXED_HASHER: FixedState =
FixedState::with_seed(0b1001010111101110000001001100010000000011001001101011001001111000);
/// Deterministic hasher based upon a random but fixed state.
#[derive(Copy, Clone, Default, Debug)]
pub struct FixedHasher;
impl BuildHasher for FixedHasher {
type Hasher = DefaultHasher;
#[inline]
fn build_hasher(&self) -> Self::Hasher {
FIXED_HASHER.build_hasher()
}
}
/// A pre-hashed value of a specific type. Pre-hashing enables memoization of hashes that are expensive to compute.
///
/// It also enables faster [`PartialEq`] comparisons by short circuiting on hash equality.
/// See [`PassHash`] and [`PassHasher`] for a "pass through" [`BuildHasher`] and [`Hasher`] implementation
/// designed to work with [`Hashed`]
/// See `PreHashMap` for a hashmap pre-configured to use [`Hashed`] keys.
pub struct Hashed<V, S = FixedHasher> {
hash: u64,
value: V,
marker: PhantomData<S>,
}
impl<V: Hash, H: BuildHasher + Default> Hashed<V, H> {
/// Pre-hashes the given value using the [`BuildHasher`] configured in the [`Hashed`] type.
pub fn new(value: V) -> Self {
Self {
hash: H::default().hash_one(&value),
value,
marker: PhantomData,
}
}
/// The pre-computed hash.
#[inline]
pub fn hash(&self) -> u64 {
self.hash
}
}
impl<V, H> Hash for Hashed<V, H> {
#[inline]
fn hash<R: Hasher>(&self, state: &mut R) {
state.write_u64(self.hash);
}
}
impl<V, H> Deref for Hashed<V, H> {
type Target = V;
#[inline]
fn deref(&self) -> &Self::Target {
&self.value
}
}
impl<V: PartialEq, H> PartialEq for Hashed<V, H> {
/// A fast impl of [`PartialEq`] that first checks that `other`'s pre-computed hash
/// matches this value's pre-computed hash.
#[inline]
fn eq(&self, other: &Self) -> bool {
self.hash == other.hash && self.value.eq(&other.value)
}
}
impl<V: Debug, H> Debug for Hashed<V, H> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Hashed")
.field("hash", &self.hash)
.field("value", &self.value)
.finish()
}
}
impl<V: Clone, H> Clone for Hashed<V, H> {
#[inline]
fn clone(&self) -> Self {
Self {
hash: self.hash,
value: self.value.clone(),
marker: PhantomData,
}
}
}
impl<V: Copy, H> Copy for Hashed<V, H> {}
impl<V: Eq, H> Eq for Hashed<V, H> {}
/// A [`BuildHasher`] that results in a [`PassHasher`].
#[derive(Default, Clone)]
pub struct PassHash;
impl BuildHasher for PassHash {
type Hasher = PassHasher;
fn build_hasher(&self) -> Self::Hasher {
PassHasher::default()
}
}
/// A no-op hash that only works on `u64`s. Will panic if attempting to
/// hash a type containing non-u64 fields.
#[derive(Debug, Default)]
pub struct PassHasher {
hash: u64,
}
impl Hasher for PassHasher {
#[inline]
fn finish(&self) -> u64 {
self.hash
}
fn write(&mut self, _bytes: &[u8]) {
panic!("can only hash u64 using PassHasher");
}
#[inline]
fn write_u64(&mut self, i: u64) {
self.hash = i;
}
}
/// [`BuildHasher`] for types that already contain a high-quality hash.
#[derive(Clone, Default)]
pub struct NoOpHash;
impl BuildHasher for NoOpHash {
type Hasher = NoOpHasher;
fn build_hasher(&self) -> Self::Hasher {
NoOpHasher(0)
}
}
#[doc(hidden)]
pub struct NoOpHasher(u64);
// This is for types that already contain a high-quality hash and want to skip
// re-hashing that hash.
impl Hasher for NoOpHasher {
fn finish(&self) -> u64 {
self.0
}
fn write(&mut self, bytes: &[u8]) {
// This should never be called by consumers. Prefer to call `write_u64` instead.
// Don't break applications (slower fallback, just check in test):
self.0 = bytes.iter().fold(self.0, |hash, b| {
hash.rotate_left(8).wrapping_add(*b as u64)
});
}
#[inline]
fn write_u64(&mut self, i: u64) {
self.0 = i;
}
}

View File

@ -15,9 +15,13 @@ extern crate std;
#[cfg(feature = "alloc")]
extern crate alloc;
pub mod hash;
pub mod sync;
pub mod time;
#[cfg(feature = "alloc")]
pub mod collections;
/// Frequently used items which would typically be included in most contexts.
///
/// When adding `no_std` support to a crate for the first time, often there's a substantial refactor

View File

@ -87,6 +87,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev", default-features
bevy_ptr = { path = "../bevy_ptr", version = "0.16.0-dev" }
bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-dev", default-features = false, features = [
"alloc",
"serialize",
] }
# used by bevy-utils, but it also needs reflect impls

View File

@ -5,8 +5,8 @@ use crate::{
DynamicEnum, Generics, PartialReflect, Type, TypePath, VariantInfo, VariantType,
};
use alloc::{boxed::Box, format, string::String};
use bevy_platform_support::collections::HashMap;
use bevy_platform_support::sync::Arc;
use bevy_utils::HashMap;
use core::slice::Iter;
/// A trait used to power [enum-like] operations via [reflection].

View File

@ -3,8 +3,8 @@ use crate::{
NamedField, UnnamedField,
};
use alloc::boxed::Box;
use bevy_platform_support::collections::HashMap;
use bevy_platform_support::sync::Arc;
use bevy_utils::HashMap;
use core::slice::Iter;
use thiserror::Error;

Some files were not shown because too many files have changed in this diff Show More