From f1675fa707a0858db13f1580db2e121db379d5ca Mon Sep 17 00:00:00 2001 From: Mica White Date: Sat, 31 Oct 2026 12:51:41 -0400 Subject: Fix storage for pre-compiled --- platforms/tortuise-script-compiled/src/storage.rs | 48 +++++++++++++++-------- 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'platforms/tortuise-script-compiled/src/storage.rs') diff --git a/platforms/tortuise-script-compiled/src/storage.rs b/platforms/tortuise-script-compiled/src/storage.rs index 033bacb..4ef272e 100644 --- a/platforms/tortuise-script-compiled/src/storage.rs +++ b/platforms/tortuise-script-compiled/src/storage.rs @@ -16,16 +16,16 @@ pub struct Config { data: Mutex>, } -pub struct StorageMut<'a, 'cx, T: Serialize + Eq> { +pub struct StorageMut<'a, 'cx, T: Serialize + Eq + Clone> { + original: &'cx Mutex>, context: &'cx mut ScriptContext<'a>, data: T, - original: T, } -pub struct ConfigMut<'a, 'cx, T: Serialize + Eq> { +pub struct ConfigMut<'a, 'cx, T: Serialize + Eq + Clone> { + original: &'cx Mutex>, context: &'cx mut ScriptContext<'a>, data: T, - original: T, } impl Storage { @@ -52,10 +52,13 @@ impl Storage { .clone() } - pub fn load_mut<'a, 'cx>(&self, context: &'cx mut ScriptContext<'a>) -> StorageMut<'a, 'cx, T> { + pub fn load_mut<'a, 'cx>( + &'cx self, + context: &'cx mut ScriptContext<'a>, + ) -> StorageMut<'a, 'cx, T> { let data = self.load(context); StorageMut { - original: data.clone(), + original: &self.data, data, context, } @@ -94,10 +97,13 @@ impl Config { .clone() } - pub fn load_mut<'a, 'cx>(&self, context: &'cx mut ScriptContext<'a>) -> StorageMut<'a, 'cx, T> { + pub fn load_mut<'a, 'cx>( + &'cx self, + context: &'cx mut ScriptContext<'a>, + ) -> StorageMut<'a, 'cx, T> { let data = self.load(context); StorageMut { - original: data.clone(), + original: &self.data, data, context, } @@ -112,7 +118,7 @@ impl Config { } } -impl Deref for StorageMut<'_, '_, T> { +impl Deref for StorageMut<'_, '_, T> { type Target = T; fn deref(&self) -> &Self::Target { @@ -120,17 +126,21 @@ impl Deref for StorageMut<'_, '_, T> { } } -impl DerefMut for StorageMut<'_, '_, T> { +impl DerefMut for StorageMut<'_, '_, T> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.data } } -impl Drop for StorageMut<'_, '_, T> { +impl Drop for StorageMut<'_, '_, T> { fn drop(&mut self) { #[cfg(feature = "profiling")] puffin::profile_function!(); - if self.data == self.original { + let mut original = self.original.lock(); + if original + .as_ref() + .is_some_and(|original| original == &self.data) + { return; } @@ -141,6 +151,7 @@ impl Drop for StorageMut<'_, '_, T> { return; } }; + *original = Some(self.data.clone()); self.context .0 .operation_queue @@ -148,7 +159,7 @@ impl Drop for StorageMut<'_, '_, T> { } } -impl Deref for ConfigMut<'_, '_, T> { +impl Deref for ConfigMut<'_, '_, T> { type Target = T; fn deref(&self) -> &Self::Target { @@ -156,17 +167,21 @@ impl Deref for ConfigMut<'_, '_, T> { } } -impl DerefMut for ConfigMut<'_, '_, T> { +impl DerefMut for ConfigMut<'_, '_, T> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.data } } -impl Drop for ConfigMut<'_, '_, T> { +impl Drop for ConfigMut<'_, '_, T> { fn drop(&mut self) { #[cfg(feature = "profiling")] puffin::profile_function!(); - if self.data == self.original { + let mut original = self.original.lock(); + if original + .as_ref() + .is_some_and(|original| original == &self.data) + { return; } @@ -177,6 +192,7 @@ impl Drop for ConfigMut<'_, '_, T> { return; } }; + *original = Some(self.data.clone()); self.context .0 .operation_queue -- cgit v1.3.1