mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
lint: enable intrange linter (#7331)
Enable intrange linter to enforce modern Go range syntax over traditional for loops, by converting: for i := 0; i < n; i++ to: for i := range n Adding type conversions where needed for compatibility with existing uint64 parameters. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
2
plugin/pkg/cache/cache.go
vendored
2
plugin/pkg/cache/cache.go
vendored
@@ -38,7 +38,7 @@ func New(size int) *Cache {
|
||||
c := &Cache{}
|
||||
|
||||
// Initialize all the shards
|
||||
for i := 0; i < shardSize; i++ {
|
||||
for i := range shardSize {
|
||||
c.shards[i] = newShard(ssize)
|
||||
}
|
||||
return c
|
||||
|
||||
10
plugin/pkg/cache/cache_test.go
vendored
10
plugin/pkg/cache/cache_test.go
vendored
@@ -13,10 +13,10 @@ func TestCacheAddAndGet(t *testing.T) {
|
||||
t.Fatal("Failed to find inserted record")
|
||||
}
|
||||
|
||||
for i := 0; i < N; i++ {
|
||||
for i := range N {
|
||||
c.Add(uint64(i), 1)
|
||||
}
|
||||
for i := 0; i < N; i++ {
|
||||
for i := range N {
|
||||
c.Add(uint64(i), 1)
|
||||
if c.Len() != N {
|
||||
t.Fatal("A item was unnecessarily evicted from the cache")
|
||||
@@ -45,7 +45,7 @@ func TestCacheLen(t *testing.T) {
|
||||
|
||||
func TestCacheSharding(t *testing.T) {
|
||||
c := New(shardSize)
|
||||
for i := 0; i < shardSize*2; i++ {
|
||||
for i := range shardSize * 2 {
|
||||
c.Add(uint64(i), 1)
|
||||
}
|
||||
for i, s := range c.shards {
|
||||
@@ -58,7 +58,7 @@ func TestCacheSharding(t *testing.T) {
|
||||
func TestCacheWalk(t *testing.T) {
|
||||
c := New(10)
|
||||
exp := make([]int, 10*2)
|
||||
for i := 0; i < 10*2; i++ {
|
||||
for i := range 10 * 2 {
|
||||
c.Add(uint64(i), 1)
|
||||
exp[i] = 1
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func BenchmarkCache(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
c := New(4)
|
||||
for n := 0; n < b.N; n++ {
|
||||
for range b.N {
|
||||
c.Add(1, 1)
|
||||
c.Get(1)
|
||||
}
|
||||
|
||||
18
plugin/pkg/cache/shard_test.go
vendored
18
plugin/pkg/cache/shard_test.go
vendored
@@ -26,11 +26,11 @@ func TestAddEvict(t *testing.T) {
|
||||
const size = 1024
|
||||
s := newShard(size)
|
||||
|
||||
for i := uint64(0); i < size; i++ {
|
||||
s.Add(i, 1)
|
||||
for i := range size {
|
||||
s.Add(uint64(i), 1)
|
||||
}
|
||||
for i := uint64(0); i < size; i++ {
|
||||
s.Add(i, 1)
|
||||
for i := range size {
|
||||
s.Add(uint64(i), 1)
|
||||
if s.Len() != size {
|
||||
t.Fatal("A item was unnecessarily evicted from the cache")
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func TestShardLenEvict(t *testing.T) {
|
||||
|
||||
// Make sure we don't accidentally evict an element when
|
||||
// we the key is already stored.
|
||||
for i := 0; i < 4; i++ {
|
||||
for range 4 {
|
||||
s.Add(5, 1)
|
||||
if l := s.Len(); l != 4 {
|
||||
t.Fatalf("Shard size should %d, got %d", 4, l)
|
||||
@@ -96,12 +96,12 @@ func TestShardLenEvict(t *testing.T) {
|
||||
|
||||
func TestShardEvictParallel(t *testing.T) {
|
||||
s := newShard(shardSize)
|
||||
for i := uint64(0); i < shardSize; i++ {
|
||||
s.Add(i, struct{}{})
|
||||
for i := range shardSize {
|
||||
s.Add(uint64(i), struct{}{})
|
||||
}
|
||||
start := make(chan struct{})
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < shardSize; i++ {
|
||||
for range shardSize {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
<-start
|
||||
@@ -119,7 +119,7 @@ func TestShardEvictParallel(t *testing.T) {
|
||||
func BenchmarkShard(b *testing.B) {
|
||||
s := newShard(shardSize)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for i := range b.N {
|
||||
k := uint64(i) % shardSize * 2
|
||||
s.Add(k, 1)
|
||||
s.Get(k)
|
||||
|
||||
Reference in New Issue
Block a user