Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/cpp/src/arrow/compute/kernels/vector_sort.cc b/cpp/src/arrow/compute/kernels/vector_sort.cc
- index 9a3aa77ee..f8ec9b52a 100644
- --- a/cpp/src/arrow/compute/kernels/vector_sort.cc
- +++ b/cpp/src/arrow/compute/kernels/vector_sort.cc
- @@ -130,28 +130,26 @@ class CountSorter {
- // first slot reserved for prefix sum, last slot for null value
- std::vector<CounterType> counts(1 + value_range + 1);
- - auto update_counts = [&](util::optional<c_type> v) {
- - if (v.has_value()) {
- - ++counts[*v - min_ + 1];
- - } else {
- - ++counts[value_range + 1];
- - }
- + auto count_notnull = [&](c_type v) {
- + ++counts[v - min_ + 1];
- + };
- + auto count_null = [&]() {
- + ++counts[value_range + 1];
- };
- - VisitArrayDataInline<ArrowType>(*values.data(), std::move(update_counts));
- + VisitArrayDataInline<ArrowType>(*values.data(), std::move(count_notnull), std::move(count_null));
- for (uint32_t i = 1; i <= value_range; ++i) {
- counts[i] += counts[i - 1];
- }
- int64_t index = 0;
- - auto write_index = [&](util::optional<c_type> v) {
- - if (v.has_value()) {
- - indices_begin[counts[*v - min_]++] = index++;
- - } else {
- - indices_begin[counts[value_range]++] = index++;
- - }
- + auto write_notnull = [&](c_type v) {
- + indices_begin[counts[v - min_]++] = index++;
- + };
- + auto write_null = [&]() {
- + indices_begin[counts[value_range]++] = index++;
- };
- - VisitArrayDataInline<ArrowType>(*values.data(), std::move(write_index));
- + VisitArrayDataInline<ArrowType>(*values.data(), std::move(write_notnull), std::move(write_null));
- }
- };
- @@ -169,13 +167,12 @@ class CountOrCompareSorter {
- c_type min{std::numeric_limits<c_type>::max()};
- c_type max{std::numeric_limits<c_type>::min()};
- - auto update_minmax = [&min, &max](util::optional<c_type> v) {
- - if (v.has_value()) {
- - min = std::min(min, *v);
- - max = std::max(max, *v);
- - }
- + auto update_notnull = [&min, &max](c_type v) {
- + min = std::min(min, v);
- + max = std::max(max, v);
- };
- - VisitArrayDataInline<ArrowType>(*values.data(), std::move(update_minmax));
- + auto update_null = []() {};
- + VisitArrayDataInline<ArrowType>(*values.data(), std::move(update_notnull), std::move(update_null));
- // For signed int32/64, (max - min) may overflow and trigger UBSAN.
- // Cast to largest unsigned type(uint64_t) before subtraction.
- if (static_cast<uint64_t>(max) - static_cast<uint64_t>(min) <=
- diff --git a/cpp/src/arrow/visitor_inline.h b/cpp/src/arrow/visitor_inline.h
- index 7a18ceb70..321b4870d 100644
- --- a/cpp/src/arrow/visitor_inline.h
- +++ b/cpp/src/arrow/visitor_inline.h
- @@ -208,6 +208,16 @@ struct ArrayDataInlineVisitor<T, enable_if_has_c_type<T>> {
- [&](int64_t i) { func(util::optional<c_type>(data[i])); },
- [&]() { func(util::optional<c_type>()); });
- }
- +
- + template <typename VisitFuncNotNull, typename VisitFuncNull>
- + static void VisitVoid(const ArrayData& arr, VisitFuncNotNull&& func_notnull, VisitFuncNull&& func_null) {
- + using c_type = typename T::c_type;
- + const c_type* data = arr.GetValues<c_type>(1);
- + detail::VisitBitBlocksVoid(
- + arr.buffers[0], arr.offset, arr.length,
- + [&](int64_t i) { func_notnull(data[i]); },
- + [&]() { func_null(); });
- + }
- };
- // Boolean
- @@ -368,6 +378,14 @@ VisitArrayDataInline(const ArrayData& arr, VisitFunc&& func) {
- std::forward<VisitFunc>(func));
- }
- +template <typename T, typename VisitFuncNotNull, typename VisitFuncNull>
- +typename internal::call_traits::enable_if_return<VisitFuncNotNull, void>::type
- +VisitArrayDataInline(const ArrayData& arr, VisitFuncNotNull&& func_notnull, VisitFuncNull&& func_null) {
- + return internal::ArrayDataInlineVisitor<T>::VisitVoid(arr,
- + std::forward<VisitFuncNotNull>(func_notnull),
- + std::forward<VisitFuncNull>(func_null));
- +}
- +
- // Visit an array's data values, in order, without overhead.
- //
- // The Visit method's `visitor` argument should be an object with two public methods:
Advertisement
Add Comment
Please, Sign In to add comment