Skip to content

Commit f99bfd8

Browse files
authored
Refactor rm unused code (#328)
* chore: init * fix: fuzz config * refactor: rm unused code
1 parent 4700ead commit f99bfd8

18 files changed

Lines changed: 136 additions & 853 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ members = [
66
"crates/rle",
77
"crates/loro-common",
88
"crates/loro-internal",
9-
"crates/loro-preload",
109
"crates/loro-wasm",
1110
"crates/fuzz",
1211
]

crates/fuzz/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ publish = false
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
loro = { path = "../loro", features = ["test_utils"] }
10+
loro = { path = "../loro" }
11+
loro-internal = { path = "../loro-internal", features = ["test_utils"] }
1112
arbitrary = "1"
1213
tabled = "0.10"
1314
debug-log = { workspace = true }

crates/fuzz/fuzz/Cargo.lock

Lines changed: 9 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/fuzz/src/container/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Actionable for TreeAction {
9393

9494
match action {
9595
TreeActionInner::Create => {
96-
let id = tree.next_tree_id();
96+
let id = tree.__internal__next_tree_id();
9797
*target = (id.peer, id.counter);
9898
}
9999
TreeActionInner::Delete => {

crates/fuzz/tests/test.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,44 @@ fn random_fuzz_1s_5sites_1() {
450450
fn random_fuzz_1s_5sites_2() {
451451
arbtest::builder().budget_ms(1000).run(|u| prop(u, 5));
452452
}
453+
454+
#[test]
455+
fn test_unknown() {
456+
test_multi_sites(
457+
5,
458+
vec![
459+
FuzzTarget::Map,
460+
FuzzTarget::List,
461+
FuzzTarget::Tree,
462+
FuzzTarget::Text,
463+
],
464+
&mut [
465+
Handle {
466+
site: 34,
467+
target: 115,
468+
container: 4,
469+
action: Generic(GenericAction {
470+
value: I32(62063364),
471+
bool: false,
472+
key: 771987715,
473+
pos: 217020518514230019,
474+
length: 217234923281646339,
475+
prop: 6234107865851074949,
476+
}),
477+
},
478+
Handle {
479+
site: 3,
480+
target: 3,
481+
container: 0,
482+
action: Generic(GenericAction {
483+
value: I32(0),
484+
bool: false,
485+
key: 0,
486+
pos: 0,
487+
length: 0,
488+
prop: 0,
489+
}),
490+
},
491+
],
492+
)
493+
}

crates/loro-common/src/span.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -491,62 +491,8 @@ impl From<ID> for IdSpan {
491491

492492
#[cfg(test)]
493493
mod test_id_span {
494-
use rle::RleVecWithIndex;
495-
496494
use super::*;
497495

498-
macro_rules! id_spans {
499-
($([$peer:expr, $from:expr, $to:expr]),*) => {
500-
{
501-
let mut id_spans = RleVecWithIndex::new();
502-
$(
503-
id_spans.push(IdSpan {
504-
peer: $peer,
505-
counter: CounterSpan::new($from, $to),
506-
});
507-
)*
508-
id_spans
509-
}
510-
};
511-
}
512-
513-
#[test]
514-
fn test_id_span_rle_vec() {
515-
let mut id_span_vec = RleVecWithIndex::new();
516-
id_span_vec.push(IdSpan {
517-
peer: 0,
518-
counter: CounterSpan::new(0, 2),
519-
});
520-
assert_eq!(id_span_vec.merged_len(), 1);
521-
assert_eq!(id_span_vec.atom_len(), 2);
522-
id_span_vec.push(IdSpan {
523-
peer: 0,
524-
counter: CounterSpan::new(2, 4),
525-
});
526-
assert_eq!(id_span_vec.merged_len(), 1);
527-
assert_eq!(id_span_vec.atom_len(), 4);
528-
id_span_vec.push(IdSpan {
529-
peer: 2,
530-
counter: CounterSpan::new(2, 4),
531-
});
532-
assert_eq!(id_span_vec.merged_len(), 2);
533-
assert_eq!(id_span_vec.atom_len(), 6);
534-
}
535-
536-
#[test]
537-
fn slice() {
538-
let id_span_vec = id_spans!([0, 0, 2], [0, 2, 4], [2, 2, 4]);
539-
let slice: Vec<IdSpan> = id_span_vec.slice_iter(2, 5).map(|x| x.into()).collect();
540-
assert_eq!(slice, id_spans!([0, 2, 4], [2, 2, 3]).to_vec());
541-
}
542-
543-
#[test]
544-
fn backward() {
545-
let id_span_vec = id_spans!([0, 100, 98], [0, 98, 90], [2, 2, 4], [2, 8, 4]);
546-
let slice: Vec<IdSpan> = id_span_vec.slice_iter(5, 14).map(|x| x.into()).collect();
547-
assert_eq!(slice, id_spans!([0, 95, 90], [2, 2, 4], [2, 8, 6]).to_vec());
548-
}
549-
550496
#[test]
551497
fn merge() {
552498
let mut a = CounterSpan::new(0, 2);

crates/loro-internal/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ keywords = ["crdt", "local-first"]
1414

1515
[dependencies]
1616
rle = { path = "../rle", version = "0.4.0", package = "loro-rle" }
17-
loro-preload = { path = "../loro-preload", version = "0.4.0" }
1817
loro-common = { path = "../loro-common", version = "0.4.0" }
1918
smallvec = { version = "1.8.0", features = ["serde"] }
2019
postcard = "1"

crates/loro-internal/examples/encoding.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::time::Instant;
2+
13
use bench_utils::TextAction;
24
use loro_internal::LoroDoc;
35

@@ -37,8 +39,15 @@ fn main() {
3739
txn.commit().unwrap();
3840
}
3941

42+
let start = Instant::now();
4043
let snapshot = loro.export_snapshot();
44+
println!("Snapshot time {}ms", start.elapsed().as_millis());
4145
let output = miniz_oxide::deflate::compress_to_vec(&snapshot, 6);
46+
println!(
47+
"Snapshot+compression time {}ms",
48+
start.elapsed().as_millis()
49+
);
50+
4251
println!(
4352
"snapshot size {} after compression {}",
4453
snapshot.len(),

crates/loro-internal/src/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,8 +2335,8 @@ impl TreeHandler {
23352335
}
23362336
}
23372337

2338-
#[cfg(feature = "test_utils")]
2339-
pub fn next_tree_id(&self) -> TreeID {
2338+
#[allow(non_snake_case)]
2339+
pub fn __internal__next_tree_id(&self) -> TreeID {
23402340
match &self.inner {
23412341
MaybeDetached::Detached(d) => {
23422342
let d = d.try_lock().unwrap();

0 commit comments

Comments
 (0)