From 2324b5196fee0029f3cc3f2859abea52d3acab1c Mon Sep 17 00:00:00 2001 From: Zachary Harrold Date: Thu, 12 Oct 2023 21:20:07 +1100 Subject: [PATCH] Removed `once_cell` (#10079) # Objective - Fixes #8303 ## Solution - Replaced 1 instance of `OnceBox` with `OnceLock` 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. --- crates/bevy_reflect/Cargo.toml | 1 - crates/bevy_reflect/src/utility.rs | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/bevy_reflect/Cargo.toml b/crates/bevy_reflect/Cargo.toml index 96884618458ee..a098d03f19e1f 100644 --- a/crates/bevy_reflect/Cargo.toml +++ b/crates/bevy_reflect/Cargo.toml @@ -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", diff --git a/crates/bevy_reflect/src/utility.rs b/crates/bevy_reflect/src/utility.rs index 71f82539f114a..75ad95b376a96 100644 --- a/crates/bevy_reflect/src/utility.rs +++ b/crates/bevy_reflect/src/utility.rs @@ -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`]. @@ -89,7 +88,7 @@ mod sealed { /// ``` /// /// [`TypePath`]: crate::TypePath -pub struct NonGenericTypeCell(OnceBox); +pub struct NonGenericTypeCell(OnceLock); /// See [`NonGenericTypeCell`]. pub type NonGenericTypeInfoCell = NonGenericTypeCell; @@ -97,7 +96,7 @@ pub type NonGenericTypeInfoCell = NonGenericTypeCell; impl NonGenericTypeCell { /// 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. @@ -107,7 +106,7 @@ impl NonGenericTypeCell { where F: FnOnce() -> T::Stored, { - self.0.get_or_init(|| Box::new(f())) + self.0.get_or_init(f) } }