From de9a8cb9ad723c78e247c046148d61e777084f03 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Mon, 10 Jul 2023 18:28:44 +0800 Subject: [PATCH] refactor: rm usage like Arc because LoroValue itself is cheap to clone now --- crates/loro-internal/src/delta/map_delta.rs | 8 ++++---- crates/loro-internal/src/refactor/arena.rs | 8 ++++---- crates/loro-internal/src/refactor/state/map_state.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/loro-internal/src/delta/map_delta.rs b/crates/loro-internal/src/delta/map_delta.rs index 405e2f0c..c3ac52d2 100644 --- a/crates/loro-internal/src/delta/map_delta.rs +++ b/crates/loro-internal/src/delta/map_delta.rs @@ -1,4 +1,4 @@ -use std::{hash::Hash, sync::Arc}; +use std::hash::Hash; use fxhash::FxHashMap; use serde::{ser::SerializeStruct, Serialize}; @@ -34,7 +34,7 @@ impl MapDelta { #[derive(Debug, Clone)] pub struct MapValue { pub counter: Counter, - pub value: Option>, + pub value: Option, pub lamport: (Lamport, PeerID), } @@ -84,14 +84,14 @@ impl Serialize for MapValue { S: serde::Serializer, { let mut s = serializer.serialize_struct("MapValue", 2)?; - s.serialize_field("value", &self.value.as_deref())?; + s.serialize_field("value", &self.value)?; s.serialize_field("lamport", &self.lamport)?; s.end() } } impl MapValue { - pub fn new(id: ID, lamport: Lamport, value: Option>) -> Self { + pub fn new(id: ID, lamport: Lamport, value: Option) -> Self { MapValue { counter: id.counter, value, diff --git a/crates/loro-internal/src/refactor/arena.rs b/crates/loro-internal/src/refactor/arena.rs index d1f08269..e4c87fab 100644 --- a/crates/loro-internal/src/refactor/arena.rs +++ b/crates/loro-internal/src/refactor/arena.rs @@ -29,7 +29,7 @@ pub(super) struct SharedArena { parents: Arc>>>, text: Arc>, text_utf16_len: Arc, - values: Arc>>>, + values: Arc>>, } pub(crate) struct StrAllocResult { @@ -89,7 +89,7 @@ impl SharedArena { pub fn alloc_value(&self, value: LoroValue) -> usize { let mut values_lock = self.values.lock().unwrap(); - values_lock.push(Arc::new(value)); + values_lock.push(value); values_lock.len() - 1 } @@ -97,7 +97,7 @@ impl SharedArena { let mut values_lock = self.values.lock().unwrap(); let start = values_lock.len(); for value in values { - values_lock.push(Arc::new(value)); + values_lock.push(value); } start..values_lock.len() @@ -115,7 +115,7 @@ impl SharedArena { self.text.lock().unwrap().slice(range) } - pub fn get_value(&self, idx: usize) -> Option> { + pub fn get_value(&self, idx: usize) -> Option { self.values.lock().unwrap().get(idx).cloned() } diff --git a/crates/loro-internal/src/refactor/state/map_state.rs b/crates/loro-internal/src/refactor/state/map_state.rs index 2f67f953..e05f706d 100644 --- a/crates/loro-internal/src/refactor/state/map_state.rs +++ b/crates/loro-internal/src/refactor/state/map_state.rs @@ -56,7 +56,7 @@ impl ContainerState for MapState { MapValue { lamport: (op.lamport, op.id.peer), counter: op.id.counter, - value: Some(Arc::new(map.value)), + value: Some(map.value), }, ), RawOpContent::List(_) => unreachable!(),