Copilot commented on code in PR #50329:
URL: https://github.com/apache/arrow/pull/50329#discussion_r3511195460
##########
cpp/src/arrow/compute/kernels/vector_select_k.cc:
##########
@@ -118,22 +117,22 @@ void HeapSortNonNullsToOutput(std::span<uint64_t>
non_null_input_range, Comparat
return;
}
std::span<uint64_t> heap = non_null_input_range.subspan(0,
output_range.size());
- std::ranges::make_heap(heap, cmp);
+ std::make_heap(heap.begin(), heap.end(), cmp);
std::span<uint64_t> remaining_input =
non_null_input_range.subspan(output_range.size());
for (uint64_t x_index : remaining_input) {
if (cmp(x_index, heap.front())) {
- std::ranges::pop_heap(heap, cmp);
+ std::pop_heap(heap.begin(), heap.end(), cmp);
heap.back() = x_index;
- std::ranges::push_heap(heap, cmp);
+ std::push_heap(heap.begin(), heap.end(), cmp);
}
}
// fill output in reverse when destructing,
// as the "worst" (next-to-would-have-been-replaced) element is at heap-top
- for (auto& reverse_out_iter : std::ranges::reverse_view(output_range)) {
- reverse_out_iter = heap.front(); // heap-top has the next element
- std::ranges::pop_heap(heap, cmp);
+ for (int64_t i = output_range.size(); i > 0; --i) {
+ output_range[i - 1] = heap.front(); // heap-top has the next element
+ std::pop_heap(heap.begin(), heap.end(), cmp);
// Decrease heap-size by one
heap = heap.first(heap.size() - 1);
Review Comment:
Loop counter is declared as int64_t but initialized from span::size()
(size_t). This implicit narrowing can trigger warnings (and is inconsistent
with other places in this file/test suite that use explicit casts). Prefer a
size_t countdown loop (or an explicit static_cast<int64_t>).
##########
cpp/src/arrow/compute/kernels/vector_select_k.cc:
##########
@@ -422,9 +421,8 @@ class ChunkedArraySelector : public TypeVisitor {
// so the heap must have been completely filled
DCHECK_EQ(heap.size(), output.non_null_like_range.size());
- for (uint64_t& reverse_out_iter :
- std::ranges::reverse_view(output.non_null_like_range)) {
- reverse_out_iter =
+ for (int64_t i = output.non_null_like_range.size(); i > 0; --i) {
+ output.non_null_like_range[i - 1] =
heap.top().index + heap.top().offset; // heap-top has the next
element
heap.pop();
}
Review Comment:
Same as above: int64_t loop counter is implicitly initialized from
span::size() (size_t). Using a size_t countdown loop avoids narrowing and
potential warnings.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]