Skip to content

Commit bb13d06

Browse files
Removed once_cell (#10079)
# Objective - Fixes #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 65d57b9 commit bb13d06

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

Diff for: crates/bevy_reflect/Cargo.toml

-1
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",

Diff for: crates/bevy_reflect/src/utility.rs

+4-5
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)