Skip to content

Commit

Permalink
Simplify ContainerChunker::push_into (#549)
Browse files Browse the repository at this point in the history
Instead of defining a closure and calling it, just inline the single use of
the closure.

Signed-off-by: Moritz Hoffmann <[email protected]>
  • Loading branch information
antiguru authored Dec 7, 2024
1 parent daae392 commit a10d3ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/consolidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ where
/// Consolidate the supplied container.
pub fn consolidate_container<C: ConsolidateLayout>(container: &mut C, target: &mut C) {
// Sort input data
let mut permutation = Vec::new();
let mut permutation = Vec::with_capacity(container.len());
permutation.extend(container.drain());
permutation.sort_by(|a, b| C::cmp(a, b));

Expand Down
24 changes: 10 additions & 14 deletions src/trace/implementations/chunker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,29 +260,25 @@ where
Input: Container,
Output: SizableContainer
+ ConsolidateLayout
+ PushInto<Input::Item<'a>>
+ PushInto<Input::ItemRef<'a>>,
+ PushInto<Input::Item<'a>>,
{
fn push_into(&mut self, container: &'a mut Input) {
self.pending.ensure_capacity(&mut None);

let form_batch = |this: &mut Self| {
if this.pending.at_capacity() {
let starting_len = this.pending.len();
consolidate_container(&mut this.pending, &mut this.empty);
std::mem::swap(&mut this.pending, &mut this.empty);
this.empty.clear();
if this.pending.len() > starting_len / 2 {
for item in container.drain() {
self.pending.push(item);
if self.pending.at_capacity() {
let starting_len = self.pending.len();
consolidate_container(&mut self.pending, &mut self.empty);
std::mem::swap(&mut self.pending, &mut self.empty);
self.empty.clear();
if self.pending.len() > starting_len / 2 {
// Note that we're pushing non-full containers, which is a deviation from
// other implementation. The reason for this is that we cannot extract
// partial data from `this.pending`. We should revisit this in the future.
this.ready.push_back(std::mem::take(&mut this.pending));
self.ready.push_back(std::mem::take(&mut self.pending));
}
}
};
for item in container.drain() {
self.pending.push(item);
form_batch(self);
}
}
}
Expand Down

0 comments on commit a10d3ca

Please sign in to comment.