fix: typo on op -> diff

This commit is contained in:
Zixuan Chen 2023-07-22 19:19:11 +08:00
parent b5c325b490
commit aa151a48f5
3 changed files with 13 additions and 9 deletions

View file

@ -44,9 +44,18 @@ mod container_idx {
// During a transaction, we may create some containers which are deleted later. And these containers also need a unique ContainerIdx.
// So when we encode snapshot, we need to sort the containers by ContainerIdx and change the `container` of ops to the index of containers.
// An empty store decodes the snapshot, it will create these containers in a sequence of natural numbers so that containers and ops can correspond one-to-one
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub struct ContainerIdx(u32);
impl std::fmt::Debug for ContainerIdx {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("ContainerIdx")
.field(&self.get_type())
.field(&self.to_index())
.finish()
}
}
impl ContainerIdx {
pub(crate) const TYPE_MASK: u32 = 0b1111 << 28;
pub(crate) const INDEX_MASK: u32 = !Self::TYPE_MASK;

View file

@ -208,7 +208,9 @@ impl DocState {
let diffs = std::mem::take(&mut recorder.diffs);
let start = recorder.diff_start_version.take().unwrap();
recorder.diff_start_version = Some((*diffs.last().unwrap().new_version).to_owned());
// debug_dbg!(&diffs);
let event = self.diffs_to_event(diffs, start);
// debug_dbg!(&event);
self.event_recorder.events.push(event);
}
@ -228,8 +230,6 @@ impl DocState {
panic!("apply_diff should not be called in a transaction");
}
debug_dbg!(&diff);
debug_dbg!(self.get_deep_value());
self.pre_txn(diff.origin.clone(), diff.local);
for diff in diff.diff.iter() {
let state = self
@ -467,8 +467,6 @@ impl DocState {
panic!("diffs is empty");
}
debug_dbg!(&diffs);
let mut containers = FxHashMap::default();
let to = (*diffs.last().unwrap().new_version).to_owned();
let origin = diffs[0].origin.clone();
@ -523,11 +521,8 @@ impl DocState {
let mut idx = idx;
loop {
let id = self.arena.idx_to_id(idx).unwrap();
debug_dbg!(&id);
if let Some(parent_idx) = self.arena.get_parent(idx) {
debug_dbg!(&parent_idx);
let parent_id = self.arena.get_container_id(parent_idx);
debug_dbg!(&id, &idx, &parent_idx, &parent_id);
let parent_state = self.states.get(&parent_idx).unwrap();
let prop = parent_state.get_child_index(&id)?;
ans.push((id, prop));

View file

@ -276,7 +276,7 @@ fn change_to_diff(change: &Change, arena: &SharedArena) -> Vec<InternalContainer
.retain(*pos)
.insert(SliceRanges(smallvec![slice.clone()])),
),
InnerListOp::Delete(del) => Diff::List(
InnerListOp::Delete(del) => Diff::SeqRaw(
Delta::new()
.retain(del.pos as usize)
.delete(del.len as usize),