Skip to content

Commit 039e5b9

Browse files
committed
Improve lamda function
Signed-off-by: Mohammad Shehar Yaar Tausif <sheharyaar48@gmail.com>
1 parent d1a0285 commit 039e5b9

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/types/redis_bitmap.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,6 @@ rocksdb::Status Bitmap::BitPos(const Slice &user_key, bool bit, int64_t start, i
349349
return -1;
350350
};
351351

352-
auto range_in_byte = [](uint32_t byte_start, uint32_t byte_end, uint32_t curr_byte, uint32_t start_bit,
353-
uint32_t end_bit) -> std::pair<uint32_t, uint32_t> {
354-
if (curr_byte == byte_start && curr_byte == byte_end) return {start_bit, end_bit};
355-
if (curr_byte == byte_start) return {start_bit, 7};
356-
if (curr_byte == byte_end) return {0, end_bit};
357-
return {0, 7};
358-
};
359-
360352
LatestSnapShot ss(storage_);
361353
rocksdb::ReadOptions read_options;
362354
read_options.snapshot = ss.GetSnapShot();
@@ -371,6 +363,16 @@ rocksdb::Status Bitmap::BitPos(const Slice &user_key, bool bit, int64_t start, i
371363
start_bit_pos_in_byte = u_start % 8;
372364
stop_bit_pos_in_byte = u_stop % 8;
373365
}
366+
367+
auto range_in_byte = [start_bit_pos_in_byte, stop_bit_pos_in_byte](
368+
uint32_t byte_start, uint32_t byte_end,
369+
uint32_t curr_byte) -> std::pair<uint32_t, uint32_t> {
370+
if (curr_byte == byte_start && curr_byte == byte_end) return {start_bit_pos_in_byte, stop_bit_pos_in_byte};
371+
if (curr_byte == byte_start) return {start_bit_pos_in_byte, 7};
372+
if (curr_byte == byte_end) return {0, stop_bit_pos_in_byte};
373+
return {0, 7};
374+
};
375+
374376
// Don't use multi get to prevent large range query, and take too much memory
375377
// Searching bits in segments [start_index, stop_index].
376378
for (uint32_t i = start_segment_index; i <= stop_segment_index; i++) {
@@ -411,8 +413,7 @@ rocksdb::Status Bitmap::BitPos(const Slice &user_key, bool bit, int64_t start, i
411413
int bit_pos_in_byte_value = -1;
412414
if (is_bit_index) {
413415
uint32_t start_bit = 0, stop_bit = 7;
414-
std::tie(start_bit, stop_bit) = range_in_byte(byte_with_bit_start, byte_with_bit_stop, byte_pos_in_segment,
415-
start_bit_pos_in_byte, stop_bit_pos_in_byte);
416+
std::tie(start_bit, stop_bit) = range_in_byte(byte_with_bit_start, byte_with_bit_stop, byte_pos_in_segment);
416417
bit_pos_in_byte_value = bit_pos_in_byte_startstop(pin_value[byte_pos_in_segment], bit, start_bit, stop_bit);
417418
} else {
418419
bit_pos_in_byte_value = bit_pos_in_byte(pin_value[byte_pos_in_segment], bit);

0 commit comments

Comments
 (0)