gongxun0928 commented on code in PR #1384:
URL: https://github.com/apache/cloudberry/pull/1384#discussion_r2426231163


##########
contrib/pax_storage/src/cpp/comm/bitmap.h:
##########
@@ -134,12 +134,31 @@ struct BitmapRaw final {
     static_assert(BM_WORD_BITS == (1 << BM_WORD_SHIFTS));
     return (index >> BM_WORD_SHIFTS) < size;
   }
-  inline bool Empty() const {
+
+  
+  inline bool Empty(uint32 end_index) const {
     if (!bitmap) return true;
-    for (size_t i = 0; i < size; i++)
-      if (bitmap[i]) return false;
+    
+    uint32 end_word = BM_INDEX_WORD_OFF(end_index);
+    uint32 end_bit_offset = BM_INDEX_BIT_OFF(end_index);
+    
+    for (uint32 i = 0; i < end_word && i < size; i++) {
+      if (bitmap[i] != 0) return false;
+    }
+    
+    // Check partial word at end
+    if (end_word < size && end_bit_offset > 0) {
+      T mask = (T(1) << end_bit_offset) - 1;
+      if (bitmap[end_word] & mask) return false;
+    }

Review Comment:
   it's not a hot path, and directly using BM_INDEX_WORD_OFF is efficient and 
straightforward. It depends on the length of type T. If T is uint64_t, it 
checks in batches based on a 64-bit width. If T is uint8_t, it checks in byte. 
   
   The reason for not using uint64_t to process a uint8_t* bitmap is that the 
bitmap's address may not be 8-byte aligned, which would require copying the 
memory into a variable of type uint64_t for comparison. 



-- 
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.

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to