fix: remove unknown type on content

This commit is contained in:
Zixuan Chen 2022-11-21 20:30:20 +08:00
parent 09b77fc969
commit 780f756450
7 changed files with 15 additions and 18 deletions

7
Cargo.lock generated
View file

@ -474,6 +474,12 @@ dependencies = [
"syn 1.0.103",
]
[[package]]
name = "debug-log"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd2cce8e65a25b144661b7c661eefd89d06c5329ed9a30da8ec98c4f3fefc60b"
[[package]]
name = "derive_arbitrary"
version = "1.2.0"
@ -756,6 +762,7 @@ dependencies = [
"crdt-list",
"criterion",
"ctor",
"debug-log",
"dhat",
"enum-as-inner",
"flate2",

View file

@ -44,6 +44,7 @@ ctor = "0.1.23"
criterion = "0.4.0"
flate2 = "1.0.24"
arbtest = "0.2.0"
debug-log = "0.1.1"
# See https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html

View file

@ -188,7 +188,6 @@ impl Container for ListContainer {
}
},
InnerContent::Map(_) => unreachable!(),
InnerContent::Unknown(u) => smallvec::smallvec![RemoteContent::Unknown(u)],
}
}
@ -205,7 +204,6 @@ impl Container for ListContainer {
},
ListOp::Delete(del) => InnerContent::List(InnerListOp::Delete(del)),
},
RemoteContent::Unknown(u) => InnerContent::Unknown(u),
_ => unreachable!(),
}
}

View file

@ -145,7 +145,6 @@ impl Container for TextContainer {
let mut ans = SmallVec::new();
match content {
InnerContent::Unknown(u) => ans.push(RemoteContent::Unknown(u)),
InnerContent::List(list) => match list {
InnerListOp::Insert { slice, pos } => {
let r = slice;
@ -204,14 +203,16 @@ impl Container for TextContainer {
let slice: SliceRange = range.into();
return InnerContent::List(InnerListOp::Insert { slice, pos });
}
ListSlice::Unknown(u) => return InnerContent::Unknown(u),
ListSlice::Unknown(u) => {
return InnerContent::List(InnerListOp::Insert {
slice: SliceRange::new_unknown(u as u32),
pos,
})
}
_ => unreachable!(),
},
ListOp::Delete(del) => return InnerContent::List(InnerListOp::Delete(del)),
},
RemoteContent::Unknown(u) => {
return InnerContent::Unknown(u);
}
_ => unreachable!(),
}
}

View file

@ -312,6 +312,7 @@ impl Tracker {
self.cached_fake_current_vv
.set_end(id.inc(content.content_len() as i32));
self.all_vv.set_end(id.inc(content.content_len() as i32));
dbg!(content);
let text_content = content.as_list().expect("Content is not for list");
match text_content {
InnerListOp::Insert { slice, pos } => {

View file

@ -152,7 +152,6 @@ fn encode_changes(store: &LogStore) -> Encoded {
}
},
crate::op::RemoteContent::Dyn(_) => unreachable!(),
RemoteContent::Unknown(u) => (0, u, LoroValue::Null),
};
op_len += 1;
ops.push(OpEncoding {

View file

@ -20,7 +20,6 @@ pub enum ContentType {
#[derive(EnumAsInner, Debug, Clone)]
pub enum InnerContent {
Unknown(usize),
List(InnerListOp),
Map(InnerMapSet),
}
@ -29,7 +28,6 @@ pub enum InnerContent {
pub enum RemoteContent {
Map(MapSet),
List(ListOp),
Unknown(usize),
Dyn(Box<dyn InsertContentTrait>),
}
@ -39,7 +37,6 @@ impl Clone for RemoteContent {
Self::Map(arg0) => Self::Map(arg0.clone()),
Self::List(arg0) => Self::List(arg0.clone()),
Self::Dyn(arg0) => Self::Dyn(arg0.clone_content()),
RemoteContent::Unknown(u) => RemoteContent::Unknown(*u),
}
}
}
@ -98,7 +95,6 @@ impl HasLength for RemoteContent {
RemoteContent::Map(x) => x.content_len(),
RemoteContent::Dyn(x) => x.content_len(),
RemoteContent::List(x) => x.content_len(),
RemoteContent::Unknown(x) => *x,
}
}
}
@ -109,7 +105,6 @@ impl Sliceable for RemoteContent {
RemoteContent::Map(x) => RemoteContent::Map(x.slice(from, to)),
RemoteContent::Dyn(x) => RemoteContent::Dyn(x.slice_content(from, to)),
RemoteContent::List(x) => RemoteContent::List(x.slice(from, to)),
RemoteContent::Unknown(_) => RemoteContent::Unknown(to - from),
}
}
}
@ -141,7 +136,6 @@ impl Mergable for RemoteContent {
_ => unreachable!(),
},
RemoteContent::Dyn(x) => x.merge_content(&**_other.as_dyn().unwrap()),
RemoteContent::Unknown(x) => *x += _other.content_len(),
}
}
}
@ -149,7 +143,6 @@ impl Mergable for RemoteContent {
impl HasLength for InnerContent {
fn content_len(&self) -> usize {
match self {
InnerContent::Unknown(u) => *u,
InnerContent::List(list) => list.atom_len(),
InnerContent::Map(_) => 1,
}
@ -161,7 +154,6 @@ impl Sliceable for InnerContent {
match self {
a @ InnerContent::Map(_) => a.clone(),
InnerContent::List(x) => InnerContent::List(x.slice(from, to)),
InnerContent::Unknown(_) => InnerContent::Unknown(to - from),
}
}
}
@ -173,7 +165,6 @@ impl Mergable for InnerContent {
{
match (self, other) {
(InnerContent::List(x), InnerContent::List(y)) => x.is_mergable(y, &()),
(InnerContent::Unknown(_), InnerContent::Unknown(_)) => true,
_ => false,
}
}
@ -187,7 +178,6 @@ impl Mergable for InnerContent {
InnerContent::List(y) => x.merge(y, &()),
_ => unreachable!(),
},
InnerContent::Unknown(x) => *x += _other.content_len(),
InnerContent::Map(_) => unreachable!(),
}
}