mirror of
https://github.com/loro-dev/loro.git
synced 2024-11-24 20:20:36 +00:00
refactor: rm usage like Arc<LoroValue>
because LoroValue itself is cheap to clone now
This commit is contained in:
parent
a90668abca
commit
de9a8cb9ad
3 changed files with 9 additions and 9 deletions
|
@ -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<Arc<LoroValue>>,
|
||||
pub value: Option<LoroValue>,
|
||||
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<Arc<LoroValue>>) -> Self {
|
||||
pub fn new(id: ID, lamport: Lamport, value: Option<LoroValue>) -> Self {
|
||||
MapValue {
|
||||
counter: id.counter,
|
||||
value,
|
||||
|
|
|
@ -29,7 +29,7 @@ pub(super) struct SharedArena {
|
|||
parents: Arc<Mutex<FxHashMap<ContainerIdx, Option<ContainerIdx>>>>,
|
||||
text: Arc<Mutex<AppendOnlyBytes>>,
|
||||
text_utf16_len: Arc<AtomicUsize>,
|
||||
values: Arc<Mutex<Vec<Arc<LoroValue>>>>,
|
||||
values: Arc<Mutex<Vec<LoroValue>>>,
|
||||
}
|
||||
|
||||
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<Arc<LoroValue>> {
|
||||
pub fn get_value(&self, idx: usize) -> Option<LoroValue> {
|
||||
self.values.lock().unwrap().get(idx).cloned()
|
||||
}
|
||||
|
||||
|
|
|
@ -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!(),
|
||||
|
|
Loading…
Reference in a new issue