mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/uint64set: optimize bucket16.add and bucket16.addMulti a bit
This commit is contained in:
parent
fb935e6e2c
commit
43504ebd14
1 changed files with 10 additions and 8 deletions
|
@ -835,19 +835,22 @@ func (b *bucket16) copyTo(dst *bucket16) {
|
|||
}
|
||||
|
||||
func (b *bucket16) add(x uint16) bool {
|
||||
if b.bits == nil {
|
||||
bits := b.bits
|
||||
if bits == nil {
|
||||
return b.addToSmallPool(x)
|
||||
}
|
||||
wordNum, bitMask := getWordNumBitMask(x)
|
||||
word := &b.bits[wordNum]
|
||||
ok := *word&bitMask == 0
|
||||
*word |= bitMask
|
||||
ok := bits[wordNum]&bitMask == 0
|
||||
if ok {
|
||||
bits[wordNum] |= bitMask
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
func (b *bucket16) addMulti(a []uint64) int {
|
||||
count := 0
|
||||
if b.bits == nil {
|
||||
bits := b.bits
|
||||
if bits == nil {
|
||||
// Slow path
|
||||
for _, x := range a {
|
||||
if b.add(uint16(x)) {
|
||||
|
@ -858,11 +861,10 @@ func (b *bucket16) addMulti(a []uint64) int {
|
|||
// Fast path
|
||||
for _, x := range a {
|
||||
wordNum, bitMask := getWordNumBitMask(uint16(x))
|
||||
word := &b.bits[wordNum]
|
||||
if *word&bitMask == 0 {
|
||||
if bits[wordNum]&bitMask == 0 {
|
||||
bits[wordNum] |= bitMask
|
||||
count++
|
||||
}
|
||||
*word |= bitMask
|
||||
}
|
||||
}
|
||||
return count
|
||||
|
|
Loading…
Reference in a new issue