Update golangci-lint, resolve warnings #285

Merged
fyrchik merged 1 commit from fyrchik/frostfs-node:fix-linter into master 2023-07-26 21:07:57 +00:00
2 changed files with 16 additions and 4 deletions

View file

@ -3,6 +3,7 @@ package blobovnicza
import ( import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"math/bits"
"strconv" "strconv"
) )
@ -31,11 +32,11 @@ func bucketForSize(sz uint64) []byte {
return bucketKeyFromBounds(upperPowerOfTwo(sz)) return bucketKeyFromBounds(upperPowerOfTwo(sz))
} }
func upperPowerOfTwo(v uint64) (upperBound uint64) { func upperPowerOfTwo(v uint64) uint64 {
for upperBound = firstBucketBound; upperBound < v; upperBound *= 2 { if v <= firstBucketBound {
return firstBucketBound
} }
return 1 << bits.Len64(v-1)
return
} }
func (b *Blobovnicza) incSize(sz uint64) { func (b *Blobovnicza) incSize(sz uint64) {

View file

@ -1,6 +1,7 @@
package blobovnicza package blobovnicza
import ( import (
"fmt"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -36,3 +37,13 @@ func TestSizes(t *testing.T) {
require.Equal(t, bucketKeyFromBounds(item.upperBound), bucketForSize(item.sz)) require.Equal(t, bucketKeyFromBounds(item.upperBound), bucketForSize(item.sz))
} }
} }
func BenchmarkUpperBound(b *testing.B) {
for _, size := range []uint64{1, 1023, 65 * 1024, 40 * 1024 * 1024} {
b.Run(fmt.Sprintf("size=%d", size), func(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = upperPowerOfTwo(size)
}
})
}
}