Skip to content

Commit 239247b

Browse files
authored
Merge pull request #247 from RoaringBitmap/dlemire/fastertobytes
No longer allocate temporary memory when serializing
2 parents 4318595 + d53779d commit 239247b

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

roaringarray.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,20 +488,15 @@ func (ra *roaringArray) writeTo(w io.Writer) (n int64, err error) {
488488
nw += 2
489489
binary.LittleEndian.PutUint16(buf[2:], uint16(len(ra.keys)-1))
490490
nw += 2
491-
492-
// compute isRun bitmap
493-
var ir []byte
494-
495-
isRun := newBitmapContainer()
491+
// compute isRun bitmap without temporary allocation
492+
var runbitmapslice = buf[nw:nw+isRunSizeInBytes]
496493
for i, c := range ra.containers {
497494
switch c.(type) {
498495
case *runContainer16:
499-
isRun.iadd(uint16(i))
496+
runbitmapslice[i / 8] |= 1<<(uint(i)%8)
500497
}
501498
}
502-
// convert to little endian
503-
ir = isRun.asLittleEndianByteSlice()[:isRunSizeInBytes]
504-
nw += copy(buf[nw:], ir)
499+
nw += isRunSizeInBytes
505500
} else {
506501
binary.LittleEndian.PutUint32(buf[0:], uint32(serialCookieNoRunContainer))
507502
nw += 4

0 commit comments

Comments
 (0)