Skip to content

Commit

Permalink
perf: avoid double-allocation in rolling_apply_agg_window (#15423)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored Apr 1, 2024
1 parent b0ece1e commit effc4d6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions crates/polars-arrow/src/legacy/kernels/rolling/no_nulls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,17 @@ where
}
}

let out = (0..len)
.map(|idx| {
let (start, end) = det_offsets_fn(idx, window_size, len);
if end - start < min_periods {
None
} else {
// SAFETY:
// we are in bounds
unsafe { agg_window.update(start, end) }
}
})
.collect_trusted::<Vec<_>>();
let arr = PrimitiveArray::from(out);
let out = (0..len).map(|idx| {
let (start, end) = det_offsets_fn(idx, window_size, len);
if end - start < min_periods {
None
} else {
// SAFETY:
// we are in bounds
unsafe { agg_window.update(start, end) }
}
});
let arr = PrimitiveArray::from_trusted_len_iter(out);
Ok(Box::new(arr))
}

Expand Down

0 comments on commit effc4d6

Please sign in to comment.