Skip to content

Commit e4b4386

Browse files
committed
Remove thread local
No longer needed due to fields being handled directly, and value types always serializing as a full type map
1 parent 698f2f3 commit e4b4386

File tree

1 file changed

+1
-42
lines changed
  • crates/bevy_reflect/src/serde

1 file changed

+1
-42
lines changed

crates/bevy_reflect/src/serde/ser.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use serde::{
1010
ser::{SerializeMap, SerializeSeq},
1111
Serialize,
1212
};
13-
use std::cell::Cell;
1413

1514
use super::SerializationData;
1615

@@ -29,21 +28,6 @@ impl<'a> Serializable<'a> {
2928
}
3029
}
3130

32-
thread_local! {
33-
/// Thread-local flag indicating whether we are currently
34-
/// serializing a [`ReflectBox`] value.
35-
///
36-
/// When a [`ReflectBox`] value is detected and this flag is `false`,
37-
/// the serializer should attempt to serialize the full type map of the value.
38-
/// It should then set the flag to `true` to indicate that the map has been
39-
/// created and the inner value should be serialized as normal.
40-
///
41-
/// This is necessary to prevent infinite recursion when serializing a [`ReflectBox`].
42-
///
43-
/// [`ReflectBox`]: crate::boxed::ReflectBox
44-
static IS_BOXED: Cell<bool> = const { Cell::new(false) };
45-
}
46-
4731
/// Get the serializer for the given reflected value.
4832
///
4933
/// This function should be used in place of constructing the serializer directly,
@@ -58,28 +42,14 @@ fn get_serializer<'a>(
5842
if path.starts_with("bevy_reflect::boxed::ReflectBox<dyn") {
5943
Box::new(ReflectSerializer::new(reflect_value, type_registry))
6044
} else {
61-
Box::new(TypedReflectSerializer::new_reflect_box(
62-
reflect_value,
63-
type_registry,
64-
))
45+
Box::new(TypedReflectSerializer::new(reflect_value, type_registry))
6546
}
6647
}
6748

6849
fn get_serializable<'a, E: Error>(
6950
reflect_value: &'a dyn PartialReflect,
7051
type_registry: &'a TypeRegistry,
7152
) -> Result<Serializable<'a>, E> {
72-
let path = reflect_value.reflect_type_path();
73-
if !IS_BOXED.get() && path.starts_with("bevy_reflect::boxed::ReflectBox<dyn") {
74-
// The value is a `ReflectBox` but it has not been flagged yet.
75-
// Flag it and serialize the full type map.
76-
IS_BOXED.set(true);
77-
return Ok(Serializable::Owned(Box::new(ReflectSerializer::new(
78-
reflect_value,
79-
type_registry,
80-
))));
81-
}
82-
8353
let Some(reflect_value) = reflect_value.try_as_reflect() else {
8454
return Err(Error::custom(format_args!(
8555
"Type '{}' does not implement `Reflect`",
@@ -231,17 +201,6 @@ pub struct TypedReflectSerializer<'a> {
231201

232202
impl<'a> TypedReflectSerializer<'a> {
233203
pub fn new(value: &'a dyn PartialReflect, registry: &'a TypeRegistry) -> Self {
234-
// Check if `value` is a `ReflectBox` type.
235-
IS_BOXED.set(
236-
value
237-
.reflect_type_path()
238-
.starts_with("bevy_reflect::boxed::ReflectBox<dyn"),
239-
);
240-
Self { value, registry }
241-
}
242-
243-
fn new_reflect_box(value: &'a dyn PartialReflect, registry: &'a TypeRegistry) -> Self {
244-
IS_BOXED.set(false);
245204
Self { value, registry }
246205
}
247206
}

0 commit comments

Comments
 (0)