From a7a0b7bbf3cc56138f87a1b638d1fa3e36356067 Mon Sep 17 00:00:00 2001 From: Tpt Date: Tue, 2 Nov 2021 20:08:34 +0100 Subject: [PATCH] String garbage collector: do not decrease counters set to MAX. We do not keep track of counting beyond i32::MAX --- lib/src/storage/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/storage/mod.rs b/lib/src/storage/mod.rs index 1b525a4b..69265d4b 100644 --- a/lib/src/storage/mod.rs +++ b/lib/src/storage/mod.rs @@ -134,9 +134,14 @@ impl Storage { fn str2id_merge() -> MergeOperator { fn merge_counted_values<'a>(values: impl Iterator) -> Vec { let (counter, str) = - values.fold((0, [].as_ref()), |(prev_counter, prev_str), current| { + values.fold((0_i32, [].as_ref()), |(prev_counter, prev_str), current| { + let new_counter = i32::from_be_bytes(current[..4].try_into().unwrap()); ( - prev_counter + i32::from_be_bytes(current[..4].try_into().unwrap()), + if prev_counter == i32::MAX { + i32::MAX // We keep to max, no counting + } else { + prev_counter.saturating_add(new_counter) + }, if prev_str.is_empty() { ¤t[4..] } else {