julic20s commented on code in PR #1901:
URL: https://github.com/apache/kvrocks/pull/1901#discussion_r1405347883


##########
src/types/redis_bitmap.cc:
##########
@@ -187,17 +205,7 @@ rocksdb::Status Bitmap::SetBit(const Slice &user_key, 
uint32_t offset, bool new_
   uint32_t byte_index = (offset / 8) % kBitmapSegmentBytes;
   uint64_t used_size = index + byte_index + 1;
   uint64_t bitmap_size = std::max(used_size, metadata.size);
-  if (byte_index >= value.size()) {  // expand the bitmap
-    size_t expand_size = 0;
-    if (byte_index >= value.size() * 2) {
-      expand_size = byte_index - value.size() + 1;
-    } else if (value.size() * 2 > kBitmapSegmentBytes) {
-      expand_size = kBitmapSegmentBytes - value.size();
-    } else {
-      expand_size = value.size();
-    }
-    value.append(expand_size, 0);
-  }
+  ExpandBitmapSegment(&value, byte_index + 1);

Review Comment:
   @mapleFU byte_index is the last index will be used. It can be explained as 
`expand_size = (byte_index + 1) /* new size */ - value.size() /* old size */`;



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

Reply via email to