mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-06 12:25:03 +00:00
fix: update deps
This commit is contained in:
parent
2ab2a7c84b
commit
cc3a869ee4
2 changed files with 16 additions and 25 deletions
|
@ -27,7 +27,7 @@ fn main() {
|
|||
None,
|
||||
))
|
||||
.unwrap();
|
||||
let json1 = loro.to_json();
|
||||
let json_ori = loro.to_json();
|
||||
|
||||
println!(
|
||||
"encode changes {} bytes, used {}ms",
|
||||
|
@ -46,7 +46,7 @@ fn main() {
|
|||
let mut loro = LoroCore::default();
|
||||
let start = Instant::now();
|
||||
loro.decode(&buf).unwrap();
|
||||
println!("decode changes used {}ms", start.elapsed().as_millis());
|
||||
println!("decode rle_updates used {}ms", start.elapsed().as_millis());
|
||||
let buf2 = loro
|
||||
.encode(EncodeConfig::new(
|
||||
EncodeMode::RleUpdates(VersionVector::new()),
|
||||
|
@ -55,7 +55,7 @@ fn main() {
|
|||
.unwrap();
|
||||
assert_eq!(buf, buf2);
|
||||
let json2 = loro.to_json();
|
||||
assert_eq!(json1, json2);
|
||||
assert_eq!(json_ori, json2);
|
||||
|
||||
let start = Instant::now();
|
||||
let mut loro2 = LoroCore::default();
|
||||
|
@ -64,15 +64,22 @@ fn main() {
|
|||
let json3 = loro2.to_json();
|
||||
assert_eq!(json_snapshot, json3);
|
||||
|
||||
let start = Instant::now();
|
||||
let update_buf = loro
|
||||
.encode(EncodeConfig::new(
|
||||
EncodeMode::Updates(VersionVector::new()),
|
||||
None,
|
||||
))
|
||||
.unwrap();
|
||||
println!("Updates have {} bytes", update_buf.len());
|
||||
println!("encode updates {} bytes, used {}ms", update_buf.len(), start.elapsed().as_millis());
|
||||
let mut encoder = GzEncoder::new(Vec::new(), flate2::Compression::default());
|
||||
encoder.write_all(&update_buf).unwrap();
|
||||
let data = encoder.finish().unwrap();
|
||||
println!("After compress updates have {} bytes", data.len());
|
||||
let mut loro3 = LoroCore::default();
|
||||
let start = Instant::now();
|
||||
loro3.decode(&update_buf).unwrap();
|
||||
println!("decode updates used {}ms", start.elapsed().as_millis());
|
||||
let json_update = loro3.to_json();
|
||||
assert_eq!(json_ori, json_update);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ struct EncodedOp {
|
|||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct EncodedChange {
|
||||
pub(crate) ops: Vec<EncodedOp>,
|
||||
pub(crate) deps_except_self: Vec<ID>,
|
||||
pub(crate) deps: Vec<ID>,
|
||||
pub(crate) lamport_delta: u32,
|
||||
pub(crate) timestamp_delta: i64,
|
||||
}
|
||||
|
@ -91,12 +91,7 @@ where
|
|||
contents: op.contents.iter().cloned().collect(),
|
||||
})
|
||||
.collect(),
|
||||
deps_except_self: first_change
|
||||
.deps
|
||||
.iter()
|
||||
.filter(|x| x.client_id != this_client_id)
|
||||
.copied()
|
||||
.collect(),
|
||||
deps: first_change.deps.iter().copied().collect(),
|
||||
lamport_delta: 0,
|
||||
timestamp_delta: 0,
|
||||
});
|
||||
|
@ -110,12 +105,7 @@ where
|
|||
contents: op.contents.iter().cloned().collect(),
|
||||
})
|
||||
.collect(),
|
||||
deps_except_self: change
|
||||
.deps
|
||||
.iter()
|
||||
.filter(|x| x.client_id != this_client_id)
|
||||
.copied()
|
||||
.collect(),
|
||||
deps: change.deps.iter().copied().collect(),
|
||||
lamport_delta: change.lamport - last_change.lamport,
|
||||
timestamp_delta: change.timestamp - last_change.timestamp,
|
||||
});
|
||||
|
@ -141,15 +131,9 @@ fn convert_encoded_to_changes(changes: EncodedClientChanges) -> Vec<Change<Remot
|
|||
let mut counter: Counter = changes.meta.counter;
|
||||
for encoded in changes.data {
|
||||
let start_counter = counter;
|
||||
let mut deps = SmallVec::with_capacity(encoded.deps_except_self.len() + 1);
|
||||
if start_counter > 0 {
|
||||
deps.push(ID {
|
||||
client_id: changes.meta.client,
|
||||
counter: start_counter - 1,
|
||||
});
|
||||
}
|
||||
let mut deps = SmallVec::with_capacity(encoded.deps.len());
|
||||
|
||||
for dep in encoded.deps_except_self {
|
||||
for dep in encoded.deps {
|
||||
deps.push(dep);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue