From adb50569195768f1705ddcef9fc48a9914ec1f0e Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Mon, 30 Oct 2023 21:50:28 +0800 Subject: [PATCH] test: add diagnose info for id_to_cursor --- .../src/container/richtext/tracker.rs | 1 + .../container/richtext/tracker/id_to_cursor.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/crates/loro-internal/src/container/richtext/tracker.rs b/crates/loro-internal/src/container/richtext/tracker.rs index a3dd2a862..08a18e6f4 100644 --- a/crates/loro-internal/src/container/richtext/tracker.rs +++ b/crates/loro-internal/src/container/richtext/tracker.rs @@ -228,6 +228,7 @@ impl Tracker { self._checkout(from, false); self._checkout(to, true); // debug_log::debug_dbg!(from, to, &self); + self.id_to_cursor.diagnose(); self.rope.get_diff() } } diff --git a/crates/loro-internal/src/container/richtext/tracker/id_to_cursor.rs b/crates/loro-internal/src/container/richtext/tracker/id_to_cursor.rs index bcb4e153e..1773b0c85 100644 --- a/crates/loro-internal/src/container/richtext/tracker/id_to_cursor.rs +++ b/crates/loro-internal/src/container/richtext/tracker/id_to_cursor.rs @@ -162,6 +162,23 @@ impl IdToCursor { .cursor .get_insert((id.counter - list[index].counter) as usize) } + + pub fn diagnose(&self) { + let fragment_num = self.map.iter().map(|x| x.1.len()).sum::(); + let insert_pieces = self + .map + .iter() + .flat_map(|x| x.1.iter()) + .map(|x| match &x.cursor { + Cursor::Insert { set, len } => set.len(), + Cursor::Delete(_) => 0, + }) + .sum::(); + eprintln!( + "fragments:{}, insert_pieces:{}", + fragment_num, insert_pieces + ); + } } #[derive(Debug)]