Skip to content

Commit

Permalink
remove double alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 7, 2024
1 parent e99cbda commit c38636c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions crates/polars-core/src/chunked_array/ops/sort/arg_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
let mut current_end: IdxSize = 0;
let mut rev_idx: Vec<IdxSize> = Vec::with_capacity(len);
let mut i: IdxSize;
// We traverse the array , comparing consecutive elements.
// We traverse the array, comparing consecutive elements.
// We maintain the start and end indice of elements with same value.
// When we see a new element we push the previous indices in reverse order.
// We do a final reverse to get stable reverse index.
Expand Down Expand Up @@ -220,13 +220,9 @@ where
} else if (options.descending && is_sorted_flag == IsSorted::Ascending)
|| (!options.descending && is_sorted_flag == IsSorted::Descending)
{
return ChunkedArray::with_chunk(
name,
IdxArr::from_data_default(
Buffer::from((reverse_stable_no_nulls(iters, len)[..len_final]).to_vec()),
None,
),
);
let idx = reverse_stable_no_nulls(iters, len);
let idx = Buffer::from(idx).sliced(0, len_final);
return ChunkedArray::with_chunk(name, IdxArr::from_data_default(idx, None));
}
}

Expand Down

0 comments on commit c38636c

Please sign in to comment.