Skip to content

Commit

Permalink
Preserve diff allocation on compaction
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Hoffmann <[email protected]>
  • Loading branch information
antiguru committed Sep 15, 2023
1 parent a5ed004 commit e977c0c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/consolidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,20 @@ impl<A: Columnation + Data, B: Columnation + Data, C: Columnation + Semigroup> C

// Replace `self` with a new allocation.
// TODO: recycle the old `self`
let input = &std::mem::replace(self, TimelyStack::with_capacity(self.len()))[..];
let input = std::mem::replace(self, TimelyStack::with_capacity(self.len()));

let mut diff: Option<C> = None;
let mut must_clear = false;
for i in 0..(input.len()) {
// accumulate diff
if let Some(diff) = diff.as_mut() {
// we already have a diff, simply plus_equal it
diff.plus_equals(&input[i].2)
if must_clear {
diff.clone_from(&input[i].2);
must_clear = false;
} else {
// we already have a diff, simply plus_equal it
diff.plus_equals(&input[i].2)
}
} else {
// last element was undefined or different, initialize new diff
diff = Some(input[i].2.clone())
Expand All @@ -201,7 +207,8 @@ impl<A: Columnation + Data, B: Columnation + Data, C: Columnation + Semigroup> C
// element[i] != element[i+1]
// emit element[i] if accumulated diff != 0
if !diff.as_ref().map(Semigroup::is_zero).unwrap_or(true) {
self.copy_destructured(&input[i].0, &input[i].1, &diff.take().unwrap());
self.copy_destructured(&input[i].0, &input[i].1, diff.as_ref().unwrap());
must_clear = true;
}
}
}
Expand Down

0 comments on commit e977c0c

Please sign in to comment.