mirror of
https://github.com/SSLMate/certspotter.git
synced 2025-06-27 10:15:33 +02:00
merkletree: use math/bits.OnesCount64 for efficiency
This commit is contained in:
parent
4ca81ab8aa
commit
935226b047
@ -12,6 +12,7 @@ package merkletree
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/bits"
|
||||
)
|
||||
|
||||
type CollapsedTree struct {
|
||||
@ -20,12 +21,7 @@ type CollapsedTree struct {
|
||||
}
|
||||
|
||||
func calculateNumNodes(size uint64) int {
|
||||
numNodes := 0
|
||||
for size > 0 {
|
||||
numNodes += int(size & 1)
|
||||
size >>= 1
|
||||
}
|
||||
return numNodes
|
||||
return bits.OnesCount64(size)
|
||||
}
|
||||
|
||||
func EmptyCollapsedTree() *CollapsedTree {
|
||||
|
Loading…
x
Reference in New Issue
Block a user