fix: get is span should consider unapplied status

This commit is contained in:
Zixuan Chen 2022-10-14 01:43:17 +08:00
parent 6da6cd2915
commit 9080e68c89
5 changed files with 26 additions and 14 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/target /target
*.log *.log
flamegraph.svg flamegraph.svg
target

View file

@ -1,3 +1,4 @@
target target
corpus corpus
artifacts artifacts
coverage

View file

@ -18,7 +18,7 @@ crev:
cargo crev crate check cargo crev crate check
fuzz: fuzz:
cargo fuzz run yata -- -max_total_time=300 -max_len=1000 -jobs=2 cargo fuzz run yata -- -max_total_time=300 -max_len=4000 -jobs=2
flame: flame:
cargo flamegraph --example test --features=fuzzing --root cargo flamegraph --example test --features=fuzzing --root

View file

@ -7,7 +7,7 @@ use rle::{
use crate::{id::ID, span::IdSpan}; use crate::{id::ID, span::IdSpan};
use super::y_span::{StatusChange, YSpan, YSpanTreeTrait}; use super::y_span::{Status, StatusChange, YSpan, YSpanTreeTrait};
/// It stores all the [YSpan] data, including the deleted/undo ones /// It stores all the [YSpan] data, including the deleted/undo ones
/// ///
@ -80,22 +80,33 @@ impl ContentMap {
} }
} }
let next = if prev.is_some() { if prev.is_some() {
let next_cursor = cursor.next_elem_start(); let mut next_cursor = cursor.next_elem_start();
let mut ans = None; let mut ans = None;
if let Some(next_inner) = next_cursor { while let Some(next_inner) = next_cursor {
if next_inner.as_ref().status.unapplied {
let mut cursor = next_inner.unwrap(); let mut cursor = next_inner.unwrap();
cursor.offset = 0; cursor.offset = 0;
cursor.pos = Position::Start; cursor.pos = Position::Start;
ans = Some(next_inner.as_ref().id); ans = Some(next_inner.as_ref().id);
break;
} }
ans next_cursor = next_inner.next_elem_start();
} else { }
Some(cursor.as_ref().id)
};
(prev, next) (prev, ans)
} else {
while cursor.as_ref().status.unapplied {
if let Some(next) = cursor.next_elem_start() {
cursor = next;
} else {
return (prev, None);
}
}
(prev, Some(cursor.as_ref().id))
}
} else { } else {
(None, None) (None, None)
} }

View file

@ -72,7 +72,6 @@ impl YSpan {
#[inline] #[inline]
pub fn can_be_origin(&self) -> bool { pub fn can_be_origin(&self) -> bool {
debug_assert!(self.len > 0);
self.status.is_activated() self.status.is_activated()
} }