Skip to content

Commit

Permalink
chore: skip the checking if not debug_assertions (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n authored Apr 29, 2024
1 parent 996ce70 commit e5dfded
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/loro-internal/src/container/richtext/richtext_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mod text_chunk {
}

fn check(&self) {
if cfg!(debug_assertions) {
if cfg!(any(debug_assertions, test)) {
assert_eq!(self.unicode_len, self.as_str().chars().count() as i32);
assert_eq!(
self.utf16_len,
Expand Down Expand Up @@ -1904,6 +1904,10 @@ impl RichtextState {

#[allow(unused)]
pub(crate) fn check(&self) {
if !cfg!(any(debug_assertions, test)) {
return;
}

self.tree.check();
self.check_consistency_between_content_and_style_ranges();
self.check_style_anchors_appear_in_pairs();
Expand Down Expand Up @@ -2116,7 +2120,7 @@ impl RichtextState {

/// Allow StyleAnchors to appear in pairs, so that there won't be unmatched single StyleAnchors.
pub(crate) fn check_style_anchors_appear_in_pairs(&self) {
if !cfg!(debug_assertions) {
if !cfg!(any(debug_assertions, test)) {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions crates/loro-internal/src/container/richtext/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ impl Tracker {
}

fn check_vv_correctness(&self) {
if !cfg!(debug_assertions) {
return;
}

for span in self.rope.tree().iter() {
if span.id.peer == UNKNOWN_PEER_ID {
continue;
Expand All @@ -525,6 +529,10 @@ impl Tracker {
// It can only check the correctness of insertions in id_to_cursor.
// The deletions are not checked.
fn check_id_to_cursor_insertions_correctness(&self) {
if !cfg!(debug_assertions) {
return;
}

for rope_elem in self.rope.tree().iter() {
let id_span = rope_elem.id_span();
let leaf_from_start = self.id_to_cursor.get_insert(id_span.id_start()).unwrap();
Expand Down
4 changes: 4 additions & 0 deletions crates/loro-internal/src/state/movable_list_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ mod inner {

#[allow(dead_code)]
pub fn check_consistency(&self) {
if !cfg!(debug_assertions) {
return;
}

let mut failed = false;
if self.check_list_item_consistency().is_err() {
error!("list item consistency check failed, self={:#?}", self);
Expand Down
4 changes: 4 additions & 0 deletions crates/loro-internal/src/state/richtext_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ impl RichtextState {
/// Panic if inconsistent.
#[allow(unused)]
pub(crate) fn check_consistency_between_content_and_style_ranges(&mut self) {
if !cfg!(debug_assertions) {
return;
}

self.state
.get_mut()
.check_consistency_between_content_and_style_ranges();
Expand Down

0 comments on commit e5dfded

Please sign in to comment.