Skip to content

Commit e0b807e

Browse files
bushrat011899ameknite
authored andcommitted
Removed once_cell (bevyengine#10079)
# Objective - Fixes bevyengine#8303 ## Solution - Replaced 1 instance of `OnceBox<T>` with `OnceLock<T>` in `NonGenericTypeCell` ## Notes All changes are in the private side of Bevy, and appear to have no observable change in performance or compilation time. This is purely to reduce the quantity of direct dependencies in Bevy.
1 parent a1ce3a7 commit e0b807e

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

crates/bevy_reflect/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ bevy_ptr = { path = "../bevy_ptr", version = "0.12.0-dev" }
2929
erased-serde = "0.3"
3030
downcast-rs = "1.2"
3131
thiserror = "1.0"
32-
once_cell = "1.11"
3332
serde = "1"
3433
smallvec = { version = "1.6", features = [
3534
"serde",

crates/bevy_reflect/src/utility.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
33
use crate::TypeInfo;
44
use bevy_utils::{FixedState, StableHashMap};
5-
use once_cell::race::OnceBox;
65
use std::{
76
any::{Any, TypeId},
87
hash::BuildHasher,
9-
sync::{PoisonError, RwLock},
8+
sync::{OnceLock, PoisonError, RwLock},
109
};
1110

1211
/// A type that can be stored in a ([`Non`])[`GenericTypeCell`].
@@ -89,15 +88,15 @@ mod sealed {
8988
/// ```
9089
///
9190
/// [`TypePath`]: crate::TypePath
92-
pub struct NonGenericTypeCell<T: TypedProperty>(OnceBox<T::Stored>);
91+
pub struct NonGenericTypeCell<T: TypedProperty>(OnceLock<T::Stored>);
9392

9493
/// See [`NonGenericTypeCell`].
9594
pub type NonGenericTypeInfoCell = NonGenericTypeCell<TypeInfo>;
9695

9796
impl<T: TypedProperty> NonGenericTypeCell<T> {
9897
/// Initialize a [`NonGenericTypeCell`] for non-generic types.
9998
pub const fn new() -> Self {
100-
Self(OnceBox::new())
99+
Self(OnceLock::new())
101100
}
102101

103102
/// Returns a reference to the [`TypedProperty`] stored in the cell.
@@ -107,7 +106,7 @@ impl<T: TypedProperty> NonGenericTypeCell<T> {
107106
where
108107
F: FnOnce() -> T::Stored,
109108
{
110-
self.0.get_or_init(|| Box::new(f()))
109+
self.0.get_or_init(f)
111110
}
112111
}
113112

0 commit comments

Comments
 (0)