Skip to content

Commit f5d62bc

Browse files
committed
Avoid copies in take_state
14% faster based on bench
1 parent 152e91d commit f5d62bc

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

datafusion/functions-aggregate/src/first_last.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,9 @@ where
432432
EmitTo::First(n) => {
433433
// split off the first N values in seen_values
434434
//
435-
// TODO make this more efficient rather than two
436-
// copies and bitwise manipulation
437-
let first_n: BooleanBuffer = bool_buf.iter().take(n).collect();
435+
let first_n: BooleanBuffer = bool_buf.slice(0, n);
438436
// reset the existing buffer
439-
for b in bool_buf.iter().skip(n) {
440-
bool_buf_builder.append(b);
441-
}
437+
bool_buf_builder.append_buffer(&bool_buf.slice(n, bool_buf.len() - n));
442438
first_n
443439
}
444440
}

0 commit comments

Comments
 (0)