Skip to content

Commit 6f4c7e1

Browse files
committed
Refactor RleRunDecoder::GetBatchWithCount to avoid code duplication
Address review feedback by calling GetBatch instead of duplicating the fill logic. For RLE runs, counting remains O(1) since all values in the run are identical.
1 parent e4f35d1 commit 6f4c7e1

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

cpp/src/arrow/util/rle_encoding_internal.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,17 @@ class RleRunDecoder {
308308
return to_read;
309309
}
310310

311-
/// Get a batch of values and count how many equal match_value
311+
/// Get a batch of values and count how many equal match_value.
312+
/// For RLE runs, counting is O(1) because all values in the run are identical.
312313
[[nodiscard]] rle_size_t GetBatchWithCount(value_type* out, rle_size_t batch_size,
313314
rle_size_t value_bit_width,
314315
value_type match_value, int64_t* out_count) {
315-
if (ARROW_PREDICT_FALSE(remaining_count_ == 0)) {
316-
return 0;
317-
}
318-
319-
const auto to_read = std::min(remaining_count_, batch_size);
320-
std::fill(out, out + to_read, value_);
321-
if (value_ == match_value) {
316+
// Save value_ before GetBatch since it doesn't change during the call.
317+
const auto current_value = value_;
318+
const auto to_read = GetBatch(out, batch_size, value_bit_width);
319+
if (current_value == match_value) {
322320
*out_count += to_read;
323321
}
324-
remaining_count_ -= to_read;
325322
return to_read;
326323
}
327324

0 commit comments

Comments
 (0)