diff --git a/src/consolidation.rs b/src/consolidation.rs index deb859fa5..a361e7e45 100644 --- a/src/consolidation.rs +++ b/src/consolidation.rs @@ -311,7 +311,7 @@ where /// Consolidate the supplied container. pub fn consolidate_container(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)); diff --git a/src/trace/implementations/chunker.rs b/src/trace/implementations/chunker.rs index 40553897c..0b76e9012 100644 --- a/src/trace/implementations/chunker.rs +++ b/src/trace/implementations/chunker.rs @@ -260,29 +260,25 @@ where Input: Container, Output: SizableContainer + ConsolidateLayout - + PushInto> - + PushInto>, + + PushInto>, { 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); } } }