mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/uint64set: optimize bucket16.addMulti a bit
This commit is contained in:
parent
aba955fa16
commit
35bb44d317
1 changed files with 15 additions and 11 deletions
|
@ -854,23 +854,27 @@ func (b *bucket16) add(x uint16) bool {
|
||||||
|
|
||||||
func (b *bucket16) addMulti(a []uint64) int {
|
func (b *bucket16) addMulti(a []uint64) int {
|
||||||
count := 0
|
count := 0
|
||||||
bits := b.bits
|
if b.bits == nil {
|
||||||
if bits == nil {
|
|
||||||
// Slow path
|
// Slow path
|
||||||
for _, x := range a {
|
for i, x := range a {
|
||||||
if b.add(uint16(x)) {
|
if b.add(uint16(x)) {
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
}
|
if b.bits != nil {
|
||||||
} else {
|
a = a[i+1:]
|
||||||
// Fast path
|
goto fastPath
|
||||||
for _, x := range a {
|
|
||||||
wordNum, bitMask := getWordNumBitMask(uint16(x))
|
|
||||||
if bits[wordNum]&bitMask == 0 {
|
|
||||||
bits[wordNum] |= bitMask
|
|
||||||
count++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
fastPath:
|
||||||
|
bits := b.bits
|
||||||
|
for _, x := range a {
|
||||||
|
wordNum, bitMask := getWordNumBitMask(uint16(x))
|
||||||
|
if bits[wordNum]&bitMask == 0 {
|
||||||
|
bits[wordNum] |= bitMask
|
||||||
|
count++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue