From 200a6dd39adcdb0e998bc718b7b977f207448659 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Fri, 3 Nov 2023 22:26:49 +0800 Subject: [PATCH] fix: warnings --- .../src/container/richtext/richtext_state.rs | 95 +------------------ .../src/container/richtext/style_range_map.rs | 29 ------ crates/loro-internal/src/fuzz.rs | 2 +- crates/loro-wasm/src/lib.rs | 1 + 4 files changed, 4 insertions(+), 123 deletions(-) diff --git a/crates/loro-internal/src/container/richtext/richtext_state.rs b/crates/loro-internal/src/container/richtext/richtext_state.rs index 31aea82d7..80597ad78 100644 --- a/crates/loro-internal/src/container/richtext/richtext_state.rs +++ b/crates/loro-internal/src/container/richtext/richtext_state.rs @@ -9,7 +9,7 @@ use serde::{ser::SerializeStruct, Serialize}; use std::fmt::{Display, Formatter}; use std::{ ops::{Add, AddAssign, Range, Sub}, - str::{from_utf8_unchecked, Utf8Error}, + str::Utf8Error, sync::Arc, }; @@ -32,7 +32,7 @@ use self::{ use super::{ query_by_len::{IndexQuery, QueryByLen}, - style_range_map::{StyleRangeMap, Styles, EMPTY_STYLES}, + style_range_map::{StyleRangeMap, Styles}, AnchorType, RichtextSpan, StyleOp, }; @@ -1449,97 +1449,6 @@ impl RichtextState { .annotate(range.start..range.end + 2, style); } - // FIXME: tests (unstable) - /// iter item is (event_length, styles) - pub fn iter_styles_in_event_index_range( - &self, - target_event_range: Range, - ) -> impl Iterator + '_ { - let start = self - .tree - .query::(&target_event_range.start); - let start_entity_index = match start { - Some(start) => self.get_entity_index_from_path(start.cursor), - None => 0, - }; - - let mut event_index = target_event_range.start; - let mut entity_index = start_entity_index; - let mut style_range_iter = self.style_ranges.iter_from(start_entity_index); - let mut cur_style_range = style_range_iter - .next() - .unwrap_or_else(|| (start_entity_index..usize::MAX, &EMPTY_STYLES)); - let mut text_iter = self.tree.iter_range( - start.map(|x| x.cursor).unwrap_or_else(|| Cursor { - leaf: self.tree.first_leaf().unwrap_leaf().into(), - offset: 0, - }).., - ); - let mut last_emit_event_index = target_event_range.start; - std::iter::from_fn(move || loop { - if entity_index >= cur_style_range.0.end { - let ans = cur_style_range.1; - cur_style_range = style_range_iter - .next() - .unwrap_or_else(|| (entity_index..usize::MAX, &EMPTY_STYLES)); - let len = event_index - last_emit_event_index; - last_emit_event_index = event_index; - return Some((len, ans)); - } - - if event_index >= target_event_range.end { - if last_emit_event_index < target_event_range.end { - let ans = cur_style_range.1; - let len = target_event_range.end - last_emit_event_index; - last_emit_event_index = target_event_range.end; - return Some((len, ans)); - } else { - return None; - } - } - - let Some(slice) = text_iter.next() else { - if event_index > last_emit_event_index { - let ans = cur_style_range.1; - let len = event_index - last_emit_event_index; - last_emit_event_index = event_index; - return Some((len, ans)); - } else { - return None; - } - }; - - let start_offset = slice.start.unwrap_or(0); - let elem = slice.elem; - match elem { - RichtextStateChunk::Text { unicode_len, text } => { - event_index += if cfg!(feature = "wasm") { - if start_offset == 0 { - count_utf16_chars(text) - } else { - let offset = unicode_to_utf8_index( - // SAFETY: we know that the text is valid utf8 - unsafe { from_utf8_unchecked(text) }, - start_offset, - ) - .unwrap(); - count_utf16_chars(&text[offset..]) - } - } else if start_offset == 0 { - *unicode_len as usize - } else { - *unicode_len as usize - start_offset - }; - - entity_index += *unicode_len as usize; - } - RichtextStateChunk::Style { .. } => { - entity_index += 1; - } - } - }) - } - pub fn iter(&self) -> impl Iterator + '_ { let mut entity_index = 0; let mut style_range_iter = self.style_ranges.iter(); diff --git a/crates/loro-internal/src/container/richtext/style_range_map.rs b/crates/loro-internal/src/container/richtext/style_range_map.rs index 842bfb10b..966dbf540 100644 --- a/crates/loro-internal/src/container/richtext/style_range_map.rs +++ b/crates/loro-internal/src/container/richtext/style_range_map.rs @@ -211,30 +211,6 @@ impl StyleRangeMap { }) } - pub fn iter_from( - &self, - start_entity_index: usize, - ) -> impl Iterator, &Styles)> + '_ { - let start = self - .tree - .query::(&start_entity_index) - .unwrap(); - let mut index = start_entity_index - start.offset(); - self.tree - .iter_range(start.cursor()..) - .filter_map(move |elem| { - let len = elem.elem.len; - let value = &elem.elem.styles; - let range = index.max(start_entity_index)..index + len; - index += len; - if elem.elem.styles.is_empty() { - return None; - } - - Some((range, value)) - }) - } - pub fn delete(&mut self, range: Range) { if !self.has_style { return; @@ -254,11 +230,6 @@ impl StyleRangeMap { self.tree.drain(start..end); } - #[allow(unused)] - pub fn len(&self) -> usize { - *self.tree.root_cache() as usize - } - pub(crate) fn has_style(&self) -> bool { self.has_style } diff --git a/crates/loro-internal/src/fuzz.rs b/crates/loro-internal/src/fuzz.rs index d6f87fca6..53c653b37 100644 --- a/crates/loro-internal/src/fuzz.rs +++ b/crates/loro-internal/src/fuzz.rs @@ -334,7 +334,7 @@ pub fn change_pos_to_char_boundary(pos: &mut usize, len: usize) { *pos %= len + 1; } -fn check_synced(sites: &mut [LoroDoc], texts: &[Arc>>]) { +fn check_synced(sites: &mut [LoroDoc], _: &[Arc>>]) { for i in 0..sites.len() - 1 { for j in i + 1..sites.len() { debug_log::group!("checking {} with {}", i, j); diff --git a/crates/loro-wasm/src/lib.rs b/crates/loro-wasm/src/lib.rs index b8d4c2353..3ccba89b8 100644 --- a/crates/loro-wasm/src/lib.rs +++ b/crates/loro-wasm/src/lib.rs @@ -22,6 +22,7 @@ mod convert; #[wasm_bindgen(js_name = setPanicHook)] pub fn set_panic_hook() { + #[cfg(feature = "console_error_panic_hook")] console_error_panic_hook::set_once(); }