String garbage collector: do not decrease counters set to MAX.

We do not keep track of counting beyond i32::MAX
pull/171/head
Tpt 3 years ago
parent 0c9a46fcd1
commit a7a0b7bbf3
  1. 9
      lib/src/storage/mod.rs

@ -134,9 +134,14 @@ impl Storage {
fn str2id_merge() -> MergeOperator {
fn merge_counted_values<'a>(values: impl Iterator<Item = &'a [u8]>) -> Vec<u8> {
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() {
&current[4..]
} else {

Loading…
Cancel
Save