refactor: fix warning and remove dead codes

This commit is contained in:
Zixuan Chen 2022-11-18 21:16:29 +08:00
parent fb711d22a9
commit 8f7a5a08e0
11 changed files with 33 additions and 74 deletions

12
.vscode/settings.json vendored
View file

@ -1,5 +1,15 @@
{
"cSpell.words": ["Leeeon", "smstring", "thiserror", "yspan"],
"cSpell.words": [
"arbtest",
"flate",
"Leeeon",
"LOGSTORE",
"Peritext",
"smstring",
"thiserror",
"txns",
"yspan"
],
"rust-analyzer.runnableEnv": {
"RUST_BACKTRACE": "full"
},

View file

@ -47,7 +47,7 @@ mod run {
let json: Value = serde_json::from_str(&s).unwrap();
let txns = json.as_object().unwrap().get("txns");
println!("{}", txns.unwrap().as_array().unwrap().len());
let mut b = c.benchmark_group("directapply");
let mut b = c.benchmark_group("direct_apply");
b.bench_function("B4", |b| {
b.iter(|| {
let mut loro = LoroCore::default();

View file

@ -67,6 +67,7 @@ impl StringPool {
}
#[inline(always)]
#[allow(unused)]
pub fn slice(&self, range: Range<u32>) -> &str {
std::str::from_utf8(&self.data[range.start as usize..range.end as usize]).unwrap()
}

View file

@ -109,14 +109,6 @@ impl ListSlice {
}
}
pub(super) fn new_unknown_text(len: usize) -> ListSlice {
ListSlice::Unknown(len)
}
pub(super) fn is_unknown_text(a: &ListSlice) -> bool {
a.as_unknown().is_some()
}
impl HasLength for ListSlice {
fn content_len(&self) -> usize {
match self {

View file

@ -1,13 +1,13 @@
use std::ops::{Deref, DerefMut};
use rle::{
rle_tree::{Position, SafeCursor, SafeCursorMut},
rle_tree::{Position, SafeCursor},
HasLength, RleTree, RleVecWithLen,
};
use crate::{container::text::text_content::SliceRange, id::ID, span::IdSpan};
use super::y_span::{StatusChange, YSpan, YSpanTreeTrait};
use super::y_span::{YSpan, YSpanTreeTrait};
/// It stores all the [YSpan] data, including the deleted/undo ones
///
@ -121,6 +121,7 @@ impl ContentMap {
ans
}
#[allow(unused)]
pub fn get_id_spans(&self, pos: usize, len: usize) -> RleVecWithLen<[IdSpan; 2]> {
let mut ans = RleVecWithLen::new();
for cursor in self.iter_range(pos, Some(pos + len)) {
@ -150,13 +151,3 @@ impl DerefMut for ContentMap {
&mut self.0
}
}
pub(super) fn change_status(
cursor: &mut SafeCursorMut<'_, YSpan, YSpanTreeTrait>,
change: StatusChange,
) {
let value = cursor.as_mut();
if value.status.apply(change) {
cursor.update_cache_recursively();
}
}

View file

@ -8,7 +8,7 @@ use enum_as_inner::EnumAsInner;
use rle::{
range_map::RangeMap,
rle_tree::{node::LeafNode, Position, SafeCursor, SafeCursorMut, UnsafeCursor},
rle_tree::{node::LeafNode, Position, SafeCursor, UnsafeCursor},
HasLength, Mergable, RleVecWithLen, Sliceable, ZeroElement,
};
@ -116,32 +116,6 @@ impl Marker {
Marker::Delete(_) => unreachable!(),
}
}
/// # Safety
///
/// It's safe when you are sure that the returned cursor is the only reference to the target yspan tree
pub unsafe fn as_cursor_mut(
&mut self,
id: ID,
) -> Option<SafeCursorMut<'static, YSpan, YSpanTreeTrait>> {
match self {
Marker::Insert { ptr, len: _ } => {
let node = ptr.as_ref();
let position = node.children().iter().position(|x| x.contain_id(id))?;
let child = &node.children()[position];
let start_counter = child.id.counter;
let offset = id.counter - start_counter;
Some(SafeCursorMut::new(
*ptr,
position,
offset as usize,
Position::from_offset(offset as isize, child.atom_len()),
0,
))
}
Marker::Delete(_) => None,
}
}
}
impl Sliceable for Marker {

View file

@ -4,9 +4,7 @@ use enum_as_inner::EnumAsInner;
use tabled::{TableIteratorExt, Tabled};
pub mod recursive;
use crate::{
array_mut_ref, container::registry::ContainerWrapper, debug_log, id::ClientID, LoroCore,
};
use crate::{array_mut_ref, debug_log, id::ClientID, LoroCore};
#[derive(arbitrary::Arbitrary, EnumAsInner, Clone, PartialEq, Eq, Debug)]
pub enum Action {
@ -181,7 +179,7 @@ impl Actionable for Vec<LoroCore> {
Action::Del { pos, len, site } => {
*site %= self.len() as u8;
let text = self[*site as usize].get_text("text");
if text.len() == 0 {
if text.is_empty() {
*len = 0;
*pos = 0;
return;
@ -248,7 +246,7 @@ pub fn test_single_client(mut actions: Vec<Action>) {
text_container.insert(&store, *pos, &content.to_string());
}
Action::Del { pos, len, .. } => {
if text_container.len() == 0 {
if text_container.is_empty() {
return;
}
@ -313,6 +311,7 @@ where
let f_ref: usize = f_ref as usize;
let actions_clone = actions.clone();
let action_ref: usize = (&actions_clone) as *const _ as usize;
#[allow(clippy::blocks_in_if_conditions)]
if std::panic::catch_unwind(|| {
// SAFETY: test
let f = unsafe { &*(f_ref as *const F) };
@ -341,6 +340,7 @@ where
let f_ref: usize = f_ref as usize;
let actions_clone = candidate.clone();
let action_ref: usize = (&actions_clone) as *const _ as usize;
#[allow(clippy::blocks_in_if_conditions)]
if std::panic::catch_unwind(|| {
// SAFETY: test
let f = unsafe { &*(f_ref as *const F) };
@ -394,6 +394,7 @@ pub fn normalize(site_num: u8, actions: &mut [Action]) -> Vec<Action> {
sites.preprocess(action);
applied.push(action.clone());
let sites_ptr: *mut Vec<_> = &mut sites as *mut _;
#[allow(clippy::blocks_in_if_conditions)]
if std::panic::catch_unwind(|| {
// SAFETY: Test
let sites = unsafe { &mut *sites_ptr };

View file

@ -7,9 +7,7 @@ use tabled::{TableIteratorExt, Tabled};
use crate::{
array_mut_ref,
container::{registry::ContainerWrapper, ContainerID},
debug_log,
id::ClientID,
ContainerType, List, LoroCore, LoroValue, Map, Text,
debug_log, ContainerType, List, LoroCore, LoroValue, Map, Text,
};
#[derive(Arbitrary, EnumAsInner, Clone, PartialEq, Eq, Debug)]
@ -176,7 +174,7 @@ impl Actionable for Vec<Actor> {
.get(*container_idx as usize)
{
*key %= (list.len() as u8).max(1);
if *value == FuzzValue::Null && list.len() == 0 {
if *value == FuzzValue::Null && list.is_empty() {
// no value, cannot delete
*value = FuzzValue::I32(1);
}
@ -336,12 +334,12 @@ impl Actionable for Vec<Actor> {
} => {
let actor = &mut self[*site as usize];
let container = actor.map_containers.get_mut(*container_idx as usize);
let container = if container.is_none() {
let container = if let Some(container) = container {
container
} else {
let map = actor.loro.get_map("map");
actor.map_containers.push(map);
&mut actor.map_containers[0]
} else {
container.unwrap()
};
match value {
@ -370,6 +368,7 @@ impl Actionable for Vec<Actor> {
actor.list_containers.push(list);
&mut actor.list_containers[0]
} else {
#[allow(clippy::unnecessary_unwrap)]
container.unwrap()
};
@ -395,12 +394,12 @@ impl Actionable for Vec<Actor> {
} => {
let actor = &mut self[*site as usize];
let container = actor.text_containers.get_mut(*container_idx as usize);
let container = if container.is_none() {
let container = if let Some(container) = container {
container
} else {
let text = actor.loro.get_text("text");
actor.text_containers.push(text);
&mut actor.text_containers[0]
} else {
container.unwrap()
};
if *is_del {
container.delete(&actor.loro, *pos as usize, *value as usize);
@ -463,6 +462,7 @@ pub fn normalize(site_num: u8, actions: &mut [Action]) -> Vec<Action> {
sites.preprocess(action);
applied.push(action.clone());
let sites_ptr: *mut Vec<_> = &mut sites as *mut _;
#[allow(clippy::blocks_in_if_conditions)]
if std::panic::catch_unwind(|| {
// SAFETY: Test
let sites = unsafe { &mut *sites_ptr };

View file

@ -20,7 +20,6 @@ mod error;
pub mod fuzz;
mod loro;
mod smstring;
mod snapshot;
mod span;
#[cfg(test)]
pub mod tests;

View file

@ -11,14 +11,6 @@ mod content;
pub use content::*;
use smallvec::{smallvec, SmallVec};
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OpType {
Normal,
Undo,
Redo,
}
/// Operation is a unit of change.
///
/// It has 3 types:

View file

@ -1 +0,0 @@