Skip to content

Commit

Permalink
Removed once_cell (bevyengine#10079)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
bushrat011899 authored and ameknite committed Nov 6, 2023
1 parent a1ce3a7 commit e0b807e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
1 change: 0 additions & 1 deletion crates/bevy_reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ bevy_ptr = { path = "../bevy_ptr", version = "0.12.0-dev" }
erased-serde = "0.3"
downcast-rs = "1.2"
thiserror = "1.0"
once_cell = "1.11"
serde = "1"
smallvec = { version = "1.6", features = [
"serde",
Expand Down
9 changes: 4 additions & 5 deletions crates/bevy_reflect/src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use crate::TypeInfo;
use bevy_utils::{FixedState, StableHashMap};
use once_cell::race::OnceBox;
use std::{
any::{Any, TypeId},
hash::BuildHasher,
sync::{PoisonError, RwLock},
sync::{OnceLock, PoisonError, RwLock},
};

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

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

impl<T: TypedProperty> NonGenericTypeCell<T> {
/// Initialize a [`NonGenericTypeCell`] for non-generic types.
pub const fn new() -> Self {
Self(OnceBox::new())
Self(OnceLock::new())
}

/// Returns a reference to the [`TypedProperty`] stored in the cell.
Expand All @@ -107,7 +106,7 @@ impl<T: TypedProperty> NonGenericTypeCell<T> {
where
F: FnOnce() -> T::Stored,
{
self.0.get_or_init(|| Box::new(f()))
self.0.get_or_init(f)
}
}

Expand Down

0 comments on commit e0b807e

Please sign in to comment.