Skip to content

Commit 61fc009

Browse files
committed
FromBuffer: no-copy _isRunBitmap_
1 parent d3a8c12 commit 61fc009

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

roaringarray.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -541,28 +541,17 @@ func (ra *roaringArray) fromBuffer(buf []byte) (int64, error) {
541541
pos += 4
542542
var size uint32 // number of containers
543543
haveRunContainers := false
544-
var isRun *bitmapContainer
544+
var isRunBitmap []byte
545545

546546
// cookie header
547547
if cookie&0x0000FFFF == serialCookie {
548548
haveRunContainers = true
549549
size = uint32(uint16(cookie>>16) + 1) // number of containers
550550

551551
// create is-run-container bitmap
552-
bytesToRead := (int(size) + 7) / 8
553-
by := buf[pos : pos+bytesToRead]
554-
pos += bytesToRead
555-
isRun = newBitmapContainer()
556-
i := 0
557-
for ; len(by) >= 8; i++ {
558-
isRun.bitmap[i] = binary.LittleEndian.Uint64(by)
559-
by = by[8:]
560-
}
561-
if len(by) > 0 {
562-
bx := make([]byte, 8)
563-
copy(bx, by)
564-
isRun.bitmap[i] = binary.LittleEndian.Uint64(bx)
565-
}
552+
isRunBitmapSize := (int(size) + 7) / 8
553+
isRunBitmap = buf[pos : pos+isRunBitmapSize]
554+
pos += isRunBitmapSize
566555
} else if cookie == serialCookieNoRunContainer {
567556
size = binary.LittleEndian.Uint32(buf[pos:])
568557
pos += 4
@@ -590,7 +579,7 @@ func (ra *roaringArray) fromBuffer(buf []byte) (int64, error) {
590579
ra.keys[i] = key
591580
ra.needCopyOnWrite[i] = true
592581

593-
if haveRunContainers && isRun.contains(uint16(i)) {
582+
if haveRunContainers && isRunBitmap[i/8]&(1<<(i%8)) != 0 {
594583
// run container
595584
nr := binary.LittleEndian.Uint16(buf[pos:])
596585
pos += 2

0 commit comments

Comments
 (0)