Skip to content

Commit dd3ec0d

Browse files
committed
Fix pessimit overeading guard
1 parent bcd56dc commit dd3ec0d

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

cpp/src/arrow/util/bpacking_dispatch_internal.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,14 @@ void unpack_width(const uint8_t* in, UnpackedUInt* out, int batch_size, int bit_
192192
constexpr auto kBytesRead = UnpackerForWidth::kBytesRead;
193193

194194
if constexpr (kValuesUnpacked > 0) {
195+
const uint8_t* last_in =
196+
in + bit_util::CeilDiv(batch_size * kPackedBitWidth, 8) - kBytesRead;
195197
// Running the optimized kernel for batch extraction
196-
const int bytes_to_unpack = (batch_size * kPackedBitWidth) / 8;
197-
const int unpacker_iter_count =
198-
std::min(batch_size / kValuesUnpacked, bytes_to_unpack / kBytesRead);
199-
for (int i = 0; i < unpacker_iter_count; ++i) {
198+
while ((batch_size > kValuesUnpacked) && (in <= last_in)) {
200199
in = UnpackerForWidth::unpack(in, out);
201200
out += kValuesUnpacked;
201+
batch_size -= kValuesUnpacked;
202202
}
203-
batch_size -= unpacker_iter_count * kValuesUnpacked;
204203
}
205204

206205
// Running the epilog for the remaining values that don't fit in a kernel

0 commit comments

Comments
 (0)