From 5c6aac499313ad29c6259970eee2932a3a474188 Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Wed, 11 Oct 2023 10:12:34 +1100 Subject: [PATCH 1/2] Removed `once_cell` Replaced 1 instance of `OnceBox` with `OnceLock>` in `NonGenericTypeCell` --- crates/bevy_reflect/Cargo.toml | 1 - crates/bevy_reflect/src/utility.rs | 7 +++---- 2 files changed, 3 insertions(+), 5 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..4bf98454f66a1 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. From cbaf318b7968ee9ffe0c9ab8d0375cf6a38a5a42 Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Thu, 12 Oct 2023 08:38:20 +1100 Subject: [PATCH 2/2] Removed Redundant `Box` and Closure Allocations --- crates/bevy_reflect/src/utility.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_reflect/src/utility.rs b/crates/bevy_reflect/src/utility.rs index 4bf98454f66a1..75ad95b376a96 100644 --- a/crates/bevy_reflect/src/utility.rs +++ b/crates/bevy_reflect/src/utility.rs @@ -88,7 +88,7 @@ mod sealed { /// ``` /// /// [`TypePath`]: crate::TypePath -pub struct NonGenericTypeCell(OnceLock>); +pub struct NonGenericTypeCell(OnceLock); /// See [`NonGenericTypeCell`]. pub type NonGenericTypeInfoCell = NonGenericTypeCell; @@ -106,7 +106,7 @@ impl NonGenericTypeCell { where F: FnOnce() -> T::Stored, { - self.0.get_or_init(|| Box::new(f())) + self.0.get_or_init(f) } }