Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify ContainerChunker::push_into #549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading