diff --git a/cpp/src/arrow/array/array_nested.cc b/cpp/src/arrow/array/array_nested.cc index 03f3e5af29908..b2cf316d93cd3 100644 --- a/cpp/src/arrow/array/array_nested.cc +++ b/cpp/src/arrow/array/array_nested.cc @@ -267,7 +267,6 @@ template Result> FlattenListViewArray(const ListViewArrayT& list_view_array, MemoryPool* memory_pool) { using offset_type = typename ListViewArrayT::offset_type; - const int64_t list_view_array_offset = list_view_array.offset(); const int64_t list_view_array_length = list_view_array.length(); std::shared_ptr value_array = list_view_array.values(); @@ -282,18 +281,24 @@ Result> FlattenListViewArray(const ListViewArrayT& list_v } } - const auto* validity = list_view_array.data()->template GetValues(0, 0); const auto* offsets = list_view_array.data()->template GetValues(1); const auto* sizes = list_view_array.data()->template GetValues(2); - auto is_null_or_empty = [&](int64_t i) { - if constexpr (HasNulls) { + std::function is_null_or_empty; + const auto* validity = list_view_array.data()->template GetValues(0, 0); + const int64_t list_view_array_offset = list_view_array.offset(); + if constexpr (HasNulls) { + is_null_or_empty = [&](int64_t i) { if (!bit_util::GetBit(validity, list_view_array_offset + i)) { return true; } - } - return sizes[i] == 0; - }; + return sizes[i] == 0; + }; + } else { + ARROW_UNUSED(validity); + ARROW_UNUSED(list_view_array_offset); + is_null_or_empty = [&](int64_t i) { return sizes[i] == 0; }; + } // Index of the first valid, non-empty list-view. int64_t first_i = 0;