Skip to content

Commit a10d3ca

Browse files
authored
Simplify ContainerChunker::push_into (#549)
Instead of defining a closure and calling it, just inline the single use of the closure. Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent daae392 commit a10d3ca

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/consolidation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ where
311311
/// Consolidate the supplied container.
312312
pub fn consolidate_container<C: ConsolidateLayout>(container: &mut C, target: &mut C) {
313313
// Sort input data
314-
let mut permutation = Vec::new();
314+
let mut permutation = Vec::with_capacity(container.len());
315315
permutation.extend(container.drain());
316316
permutation.sort_by(|a, b| C::cmp(a, b));
317317

src/trace/implementations/chunker.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,29 +260,25 @@ where
260260
Input: Container,
261261
Output: SizableContainer
262262
+ ConsolidateLayout
263-
+ PushInto<Input::Item<'a>>
264-
+ PushInto<Input::ItemRef<'a>>,
263+
+ PushInto<Input::Item<'a>>,
265264
{
266265
fn push_into(&mut self, container: &'a mut Input) {
267266
self.pending.ensure_capacity(&mut None);
268267

269-
let form_batch = |this: &mut Self| {
270-
if this.pending.at_capacity() {
271-
let starting_len = this.pending.len();
272-
consolidate_container(&mut this.pending, &mut this.empty);
273-
std::mem::swap(&mut this.pending, &mut this.empty);
274-
this.empty.clear();
275-
if this.pending.len() > starting_len / 2 {
268+
for item in container.drain() {
269+
self.pending.push(item);
270+
if self.pending.at_capacity() {
271+
let starting_len = self.pending.len();
272+
consolidate_container(&mut self.pending, &mut self.empty);
273+
std::mem::swap(&mut self.pending, &mut self.empty);
274+
self.empty.clear();
275+
if self.pending.len() > starting_len / 2 {
276276
// Note that we're pushing non-full containers, which is a deviation from
277277
// other implementation. The reason for this is that we cannot extract
278278
// partial data from `this.pending`. We should revisit this in the future.
279-
this.ready.push_back(std::mem::take(&mut this.pending));
279+
self.ready.push_back(std::mem::take(&mut self.pending));
280280
}
281281
}
282-
};
283-
for item in container.drain() {
284-
self.pending.push(item);
285-
form_batch(self);
286282
}
287283
}
288284
}

0 commit comments

Comments
 (0)