Skip to content

Commit

Permalink
refactor: hold doc reference in handler (#624)
Browse files Browse the repository at this point in the history
* refactor: doc arc in handler

* chore: cargo fix

* fix: clean txn arena

* chore: cargo fix

* fix: clean global txn

* fix: weak doc

* refactor: loro wasm remove arc

* chore: cargo fix
  • Loading branch information
Leeeon233 authored Jan 17, 2025
1 parent e26ee35 commit 245838f
Show file tree
Hide file tree
Showing 26 changed files with 729 additions and 921 deletions.
4 changes: 2 additions & 2 deletions crates/fuzz/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ impl Actor {
// trace!("BeforeUndo {:#?}", self.loro.get_deep_value_with_id());
// println!("\n\nstart undo\n");
for _ in 0..undo_length {
self.undo_manager.undo.undo(&self.loro).unwrap();
self.undo_manager.undo.undo().unwrap();
self.loro.commit();
}
// trace!("AfterUndo {:#?}", self.loro.get_deep_value_with_id());

// println!("\n\nstart redo\n");
for _ in 0..undo_length {
self.undo_manager.undo.redo(&self.loro).unwrap();
self.undo_manager.undo.redo().unwrap();
self.loro.commit();
}
// trace!("AfterRedo {:#?}", self.loro.get_deep_value_with_id());
Expand Down
12 changes: 6 additions & 6 deletions crates/loro-ffi/src/undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ impl UndoManager {
}

/// Undo the last change made by the peer.
pub fn undo(&self, doc: &LoroDoc) -> LoroResult<bool> {
self.0.write().unwrap().undo(doc)
pub fn undo(&self) -> LoroResult<bool> {
self.0.write().unwrap().undo()
}

/// Redo the last change made by the peer.
pub fn redo(&self, doc: &LoroDoc) -> LoroResult<bool> {
self.0.write().unwrap().redo(doc)
pub fn redo(&self) -> LoroResult<bool> {
self.0.write().unwrap().redo()
}

/// Record a new checkpoint.
pub fn record_new_checkpoint(&self, doc: &LoroDoc) -> LoroResult<()> {
self.0.write().unwrap().record_new_checkpoint(doc)
pub fn record_new_checkpoint(&self) -> LoroResult<()> {
self.0.write().unwrap().record_new_checkpoint()
}

/// Whether the undo manager can undo.
Expand Down
17 changes: 5 additions & 12 deletions crates/loro-internal/src/delta/map_delta.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use std::{
hash::Hash,
sync::{Mutex, Weak},
sync::Weak,
};

use fxhash::FxHashMap;
use loro_common::IdLp;
use serde::{ser::SerializeStruct, Serialize};

use crate::{
arena::SharedArena, change::Lamport, handler::ValueOrHandler, id::PeerID, span::HasLamport,
txn::Transaction, DocState, InternalString, LoroValue,
change::Lamport, handler::ValueOrHandler, id::PeerID, span::HasLamport, InternalString, LoroDocInner, LoroValue,
};

#[derive(Default, Debug, Clone, Serialize)]
Expand Down Expand Up @@ -66,17 +65,11 @@ pub struct ResolvedMapValue {
}

impl ResolvedMapValue {
pub(crate) fn from_map_value(
v: MapValue,
arena: &SharedArena,
txn: &Weak<Mutex<Option<Transaction>>>,
state: &Weak<Mutex<DocState>>,
) -> Self {
pub(crate) fn from_map_value(v: MapValue, doc: &Weak<LoroDocInner>) -> Self {
let doc = &doc.upgrade().unwrap();
ResolvedMapValue {
idlp: IdLp::new(v.peer, v.lamp),
value: v
.value
.map(|v| ValueOrHandler::from_value(v, arena, txn, state)),
value: v.value.map(|v| ValueOrHandler::from_value(v, doc)),
}
}

Expand Down
Loading

0 comments on commit 245838f

Please sign in to comment.