|
15 | 15 | // specific language governing permissions and limitations |
16 | 16 | // under the License. |
17 | 17 |
|
| 18 | +#include <cstdint> |
18 | 19 | #include <cstring> |
19 | 20 | #include <limits> |
20 | 21 | #include "arrow/array/builder_nested.h" |
@@ -1607,26 +1608,14 @@ Status ExecArrayCaseWhen(KernelContext* ctx, const ExecSpan& batch, ExecResult* |
1607 | 1608 |
|
1608 | 1609 | if (cond_array.GetNullCount() == 0) { |
1609 | 1610 | // If no valid buffer, visit mask & cond bitmap simultaneously |
1610 | | - BinaryBitBlockCounter counter(mask, /*start_offset=*/0, cond_values, cond_offset, |
1611 | | - batch.length); |
1612 | | - while (offset < batch.length) { |
1613 | | - const auto block = counter.NextAndWord(); |
1614 | | - if (block.AllSet()) { |
1615 | | - CopyValues<Type>(value, offset, block.length, out_valid, out_values, |
1616 | | - out_offset + offset); |
1617 | | - bit_util::SetBitsTo(mask, offset, block.length, false); |
1618 | | - } else if (block.popcount) { |
1619 | | - for (int64_t j = 0; j < block.length; ++j) { |
1620 | | - if (bit_util::GetBit(mask, offset + j) && |
1621 | | - bit_util::GetBit(cond_values, cond_offset + offset + j)) { |
1622 | | - CopyValues<Type>(value, offset + j, /*length=*/1, out_valid, out_values, |
1623 | | - out_offset + offset + j); |
1624 | | - bit_util::SetBitTo(mask, offset + j, false); |
1625 | | - } |
1626 | | - } |
1627 | | - } |
1628 | | - offset += block.length; |
1629 | | - } |
| 1611 | + auto visit_run = [&](int64_t position, int64_t run_length) { |
| 1612 | + CopyValues<Type>(value, position, run_length, out_valid, out_values, |
| 1613 | + out_offset + position); |
| 1614 | + bit_util::SetBitsTo(mask, position, run_length, false); |
| 1615 | + return Status::OK(); |
| 1616 | + }; |
| 1617 | + RETURN_NOT_OK(::arrow::internal::VisitTwoSetBitRuns( |
| 1618 | + mask, /*start_offset=*/0, cond_values, cond_offset, batch.length, visit_run)); |
1630 | 1619 | } else { |
1631 | 1620 | // Visit mask & cond bitmap & cond validity |
1632 | 1621 | const uint8_t* cond_valid = cond_array.buffers[0].data; |
@@ -1657,32 +1646,20 @@ Status ExecArrayCaseWhen(KernelContext* ctx, const ExecSpan& batch, ExecResult* |
1657 | 1646 | } |
1658 | 1647 | if (!have_else_arg) { |
1659 | 1648 | // Need to initialize any remaining null slots (uninitialized memory) |
1660 | | - BitBlockCounter counter(mask, /*offset=*/0, batch.length); |
1661 | | - int64_t offset = 0; |
1662 | 1649 | auto bit_width = checked_cast<const FixedWidthType&>(*out->type()).bit_width(); |
1663 | 1650 | auto byte_width = bit_util::BytesForBits(bit_width); |
1664 | | - while (offset < batch.length) { |
1665 | | - const auto block = counter.NextWord(); |
1666 | | - if (block.AllSet()) { |
1667 | | - if (bit_width == 1) { |
1668 | | - bit_util::SetBitsTo(out_values, out_offset + offset, block.length, false); |
1669 | | - } else { |
1670 | | - std::memset(out_values + (out_offset + offset) * byte_width, 0x00, |
1671 | | - byte_width * block.length); |
1672 | | - } |
1673 | | - } else if (!block.NoneSet()) { |
1674 | | - for (int64_t j = 0; j < block.length; ++j) { |
1675 | | - if (bit_util::GetBit(out_valid, out_offset + offset + j)) continue; |
1676 | | - if (bit_width == 1) { |
1677 | | - bit_util::ClearBit(out_values, out_offset + offset + j); |
1678 | | - } else { |
1679 | | - std::memset(out_values + (out_offset + offset + j) * byte_width, 0x00, |
1680 | | - byte_width); |
1681 | | - } |
1682 | | - } |
| 1651 | + |
| 1652 | + auto visit_run = [&](int64_t position, int64_t run_length) { |
| 1653 | + if (bit_width == 1) { |
| 1654 | + bit_util::SetBitsTo(out_values, out_offset + position, run_length, false); |
| 1655 | + } else { |
| 1656 | + std::memset(out_values + (out_offset + position) * byte_width, 0x00, |
| 1657 | + byte_width * run_length); |
1683 | 1658 | } |
1684 | | - offset += block.length; |
1685 | | - } |
| 1659 | + bit_util::SetBitsTo(mask, position, run_length, false); |
| 1660 | + }; |
| 1661 | + |
| 1662 | + ::arrow::internal::VisitSetBitRunsVoid(mask, /*offset=*/0, batch.length, visit_run); |
1686 | 1663 | } |
1687 | 1664 | return Status::OK(); |
1688 | 1665 | } |
|
0 commit comments