Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Removed un-needed unsafe. (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Jul 23, 2021
1 parent 16c089e commit b730ba7
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/compute/sort/primitive/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ where
let validity = array.validity();

let (buffer, validity) = if let Some(validity) = validity {
let nulls = (0..validity.null_count()).map(|_| false);
let valids = (validity.null_count()..array.len()).map(|_| true);
let nulls = std::iter::repeat(false).take(validity.null_count());
let valids = std::iter::repeat(true).take(array.len() - validity.null_count());

let mut buffer = MutableBuffer::<T>::with_capacity(array.len());
let mut new_validity = MutableBitmap::with_capacity(array.len());
let slices = SlicesIterator::new(validity);

if options.nulls_first {
nulls
.chain(valids)
.for_each(|value| unsafe { new_validity.push_unchecked(value) });
new_validity.extend_from_trusted_len_iter(nulls.chain(valids));
(0..validity.null_count()).for_each(|_| buffer.push(T::default()));
for (start, len) in slices {
buffer.extend_from_slice(&values[start..start + len])
Expand All @@ -67,9 +65,7 @@ where
options.descending,
)
} else {
valids
.chain(nulls)
.for_each(|value| unsafe { new_validity.push_unchecked(value) });
new_validity.extend_from_trusted_len_iter(valids.chain(nulls));
for (start, len) in slices {
buffer.extend_from_slice(&values[start..start + len])
}
Expand Down

0 comments on commit b730ba7

Please sign in to comment.