From 081485bcaf20d50cec3eb328906f16e8e89e076a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 27 Oct 2021 16:49:08 +0200 Subject: [PATCH] Make it cheaper to clone `Memory` if there are a lot of persisted values --- egui/src/util/id_type_map.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/egui/src/util/id_type_map.rs b/egui/src/util/id_type_map.rs index 2e04b6b3..9363a39f 100644 --- a/egui/src/util/id_type_map.rs +++ b/egui/src/util/id_type_map.rs @@ -4,6 +4,7 @@ // This will also allow users to pick their own serialization format per type. use std::any::Any; +use std::sync::Arc; // ----------------------------------------------------------------------------------------------- @@ -57,7 +58,7 @@ impl SerializableAny for T where T: 'static + Any + Clone + for<'a> Send + Sy #[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] struct SerializedElement { type_id: TypeId, - ron: String, + ron: Arc, } #[cfg(feature = "persistence")] @@ -82,7 +83,7 @@ enum Element { /// The type of value we are storing. type_id: TypeId, /// The ron data we can deserialize. - ron: String, + ron: Arc, }, } @@ -256,7 +257,7 @@ impl Element { let ron = serialize_fn(value)?; Some(SerializedElement { type_id: (**value).type_id().into(), - ron, + ron: ron.into(), }) } else { None