Skip to content

Commit

Permalink
[Chore] Add fixes for linters
Browse files Browse the repository at this point in the history
  • Loading branch information
maypok86 committed Aug 29, 2024
1 parent 23a97a1 commit 507bc49
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (g *generator) printStructComment() {
i := 2
for _, f := range declaredFeatures {
if g.features[f] {
//nolint:staticcheck // used only for unicode
featureTitle := strings.Title(strings.ToLower(f.name))
g.p("//")
g.p("// %d. %s", i, featureTitle)
Expand Down
13 changes: 8 additions & 5 deletions internal/core/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var (
func init() {
parallelism := xruntime.Parallelism()
roundedParallelism := int(xmath.RoundUpPowerOf2(parallelism))
//nolint:gosec // there will never be an overflow
maxWriteBufferSize = uint32(128 * roundedParallelism)
maxStripedBufferSize = 4 * roundedParallelism
}
Expand All @@ -81,6 +82,7 @@ func zeroValue[V any]() V {
}

func getTTL(ttl time.Duration) uint32 {
//nolint:gosec // there will never be an overflow
return uint32((ttl + time.Second - 1) / time.Second)
}

Expand Down Expand Up @@ -149,11 +151,12 @@ func NewCache[K comparable, V any](c Config[K, V]) *Cache[K, V] {
}

cache := &Cache[K, V]{
nodeManager: nodeManager,
hashmap: hashmap,
stripedBuffer: stripedBuffer,
writeBuffer: queue.NewGrowable[task[K, V]](minWriteBufferSize, maxWriteBufferSize),
doneClear: make(chan struct{}),
nodeManager: nodeManager,
hashmap: hashmap,
stripedBuffer: stripedBuffer,
writeBuffer: queue.NewGrowable[task[K, V]](minWriteBufferSize, maxWriteBufferSize),
doneClear: make(chan struct{}),
//nolint:gosec // there will never be an overflow
mask: uint32(maxStripedBufferSize - 1),
costFunc: c.CostFunc,
deletionListener: c.DeletionListener,
Expand Down
1 change: 1 addition & 0 deletions internal/hashtable/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func newMap[K comparable, V any](nodeManager *node.Manager[K, V], size int) *Map
if size <= minNodeCount {
t = newTable(minBucketCount, maphash.NewHasher[K]())
} else {
//nolint:gosec // there will never be an overflow
bucketCount := xmath.RoundUpPowerOf2(uint32(size / bucketSize))
t = newTable(int(bucketCount), maphash.NewHasher[K]())
}
Expand Down
2 changes: 2 additions & 0 deletions internal/lossy/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (b *Buffer[K, V]) Add(n node.Node[K, V]) *PolicyBuffers[K, V] {
}
if b.tail.CompareAndSwap(tail, tail+1) {
// success
//nolint:gosec // there will never be an overflow
index := int(tail & mask)
atomic.StorePointer(&b.buffer[index], n.AsPointer())
if size == capacity-1 {
Expand All @@ -97,6 +98,7 @@ func (b *Buffer[K, V]) Add(n node.Node[K, V]) *PolicyBuffers[K, V] {

pb := (*PolicyBuffers[K, V])(b.policyBuffers)
for i := 0; i < capacity; i++ {
//nolint:gosec // there will never be an overflow
index := int(head & mask)
v := atomic.LoadPointer(&b.buffer[index])
if v != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/unixtime/unixtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func startTimer() {
for {
select {
case t := <-ticker.C:
//nolint:gosec // there will never be an overflow
atomic.StoreUint32(&now, uint32(t.Unix()-StartTime()))
case <-done:
return
Expand Down
1 change: 1 addition & 0 deletions internal/xruntime/runtime_1.22.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ import (
)

func Fastrand() uint32 {
//nolint:gosec // we don't need a cryptographically secure random number generator
return rand.Uint32()
}
2 changes: 2 additions & 0 deletions internal/xruntime/xruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const (

// Parallelism returns the maximum possible number of concurrently running goroutines.
func Parallelism() uint32 {
//nolint:gosec // there will never be an overflow
maxProcs := uint32(runtime.GOMAXPROCS(0))
//nolint:gosec // there will never be an overflow
numCPU := uint32(runtime.NumCPU())
if maxProcs < numCPU {
return maxProcs
Expand Down

0 comments on commit 507bc49

Please sign in to comment.