emkornfield commented on a change in pull request #7143:
URL: https://github.com/apache/arrow/pull/7143#discussion_r434315391



##########
File path: cpp/src/arrow/util/bit_util.cc
##########
@@ -411,6 +411,66 @@ Result<std::shared_ptr<Buffer>> BitmapOp(MemoryPool* pool, 
const uint8_t* left,
 
 }  // namespace
 
+BitRunReader::BitRunReader(const uint8_t* bitmap, int64_t start_offset, 
int64_t length)
+    : bitmap_(bitmap + (start_offset / 8)),
+      position_(start_offset % 8),
+      length_(position_ + length) {
+  if (ARROW_PREDICT_FALSE(length == 0)) {
+    word_ = 0;
+    return;
+  }
+
+  // Prepare for inversion in NextRun.
+  current_run_bit_set_ = !BitUtil::GetBit(bitmap, start_offset);
+  LoadWord();
+  // Clear out any preceding bits.
+  word_ = word_ & ~BitUtil::PartialWordMask(position_);
+}
+
+void BitRunReader::AdvanceTillChange() {
+  int64_t new_bits = 0;
+  do {
+    // Advance the position of the bitmap for loading.
+    bitmap_ += sizeof(uint64_t);
+    LoadWord();
+    new_bits = BitUtil::CountTrailingZeros(word_);
+    // Continue calculating run length.
+    position_ += new_bits;
+  } while (ARROW_PREDICT_FALSE(position_ % 64 == 0) &&
+           ARROW_PREDICT_TRUE(position_ < length_) && new_bits > 0);
+}
+
+void BitRunReader::LoadWord() {
+  word_ = 0;
+  // On the initial load if there is an offset we need to account for this when

Review comment:
       Changing to have a separate function.  This is intentionally not inlined 
as part of the main loop (it was a performance improvement to move 
AdvanceTillChange out-of-line.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to