From 116190c81768c10188feafe41d862f98845419cd Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Wed, 8 Nov 2023 14:18:01 +0800 Subject: [PATCH] chore: refine err msg --- crates/loro-internal/examples/encoding.rs | 68 ++++++++++--------- .../src/container/richtext/richtext_state.rs | 2 +- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/crates/loro-internal/examples/encoding.rs b/crates/loro-internal/examples/encoding.rs index 3c0d9adb..7dac254d 100644 --- a/crates/loro-internal/examples/encoding.rs +++ b/crates/loro-internal/examples/encoding.rs @@ -1,43 +1,49 @@ -use std::time::Instant; - use bench_utils::TextAction; use loro_internal::LoroDoc; fn main() { let actions = bench_utils::get_automerge_actions(); - let loro = LoroDoc::default(); - let loro_b = LoroDoc::default(); - let text = loro.get_text("text"); - let mut i = 0; - let start = Instant::now(); - for TextAction { pos, ins, del } in actions.iter() { - { - let mut txn = loro.txn().unwrap(); - text.delete(&mut txn, *pos, *del).unwrap(); - text.insert(&mut txn, *pos, ins).unwrap(); - } + // let loro = LoroDoc::default(); + // let loro_b = LoroDoc::default(); + // let text = loro.get_text("text"); + // let mut i = 0; + // let start = Instant::now(); + // for TextAction { pos, ins, del } in actions.iter() { + // { + // let mut txn = loro.txn().unwrap(); + // text.delete(&mut txn, *pos, *del).unwrap(); + // text.insert(&mut txn, *pos, ins).unwrap(); + // } - loro_b - .import(&loro.export_from(&loro_b.oplog_vv())) - .unwrap(); - i += 1; - if i == 30000 { - break; - } + // loro_b + // .import(&loro.export_from(&loro_b.oplog_vv())) + // .unwrap(); + // i += 1; + // if i == 30000 { + // break; + // } + // } + + // println!("{}ms", start.elapsed().as_millis()); + + let loro = LoroDoc::default(); + let text = loro.get_text("text"); + + for TextAction { pos, ins, del } in actions.iter() { + let mut txn = loro.txn().unwrap(); + text.delete(&mut txn, *pos, *del).unwrap(); + text.insert(&mut txn, *pos, ins).unwrap(); + txn.commit().unwrap(); } - println!("{}ms", start.elapsed().as_millis()); - - // let loro = LoroDoc::default(); - // let text = loro.get_text("text"); - - // for TextAction { pos, ins, del } in actions.iter() { - // let mut txn = loro.txn().unwrap(); - // text.delete(&mut txn, *pos, *del).unwrap(); - // text.insert(&mut txn, *pos, ins).unwrap(); - // txn.commit().unwrap(); - // } + let snapshot = loro.export_snapshot(); + let output = miniz_oxide::deflate::compress_to_vec(&snapshot, 6); + println!( + "snapshot size {} after compression {}", + snapshot.len(), + output.len() + ); // { // // Delta encoding diff --git a/crates/loro-internal/src/container/richtext/richtext_state.rs b/crates/loro-internal/src/container/richtext/richtext_state.rs index 5bfa13e5..e0157fde 100644 --- a/crates/loro-internal/src/container/richtext/richtext_state.rs +++ b/crates/loro-internal/src/container/richtext/richtext_state.rs @@ -1547,7 +1547,7 @@ impl RichtextState { "pos: {}, len: {}, self.len(): {}", pos, len, - &self.to_string() + &self.len_entity(), ); // PERF: may use cache to speed up self.cursor_cache.invalidate();