From 40402fdac3d74380d6a92eab843de22aa2c8d87b Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 18 Feb 2026 13:28:11 +0100 Subject: [PATCH] lib: run `go fix -rangeint` --- lib/atomicutil/slice_test.go | 8 ++-- lib/atomicutil/slice_timing_test.go | 6 +-- lib/backup/actions/util.go | 4 +- lib/blockcache/blockcache_test.go | 4 +- lib/blockcache/blockcache_timing_test.go | 4 +- lib/bloomfilter/filter.go | 4 +- lib/bloomfilter/filter_test.go | 10 ++--- lib/bloomfilter/filter_timing_test.go | 8 ++-- lib/bloomfilter/limiter_test.go | 12 +++--- lib/bytesutil/bytesutil_test.go | 8 ++-- lib/bytesutil/fast_string_matcher_test.go | 2 +- lib/bytesutil/fast_string_transformer_test.go | 2 +- lib/bytesutil/internstring_test.go | 6 +-- lib/bytesutil/itoa_test.go | 2 +- lib/chunkedbuffer/buffer_test.go | 2 +- lib/consistenthash/consistent_hash_test.go | 2 +- .../consistent_hash_timing_test.go | 2 +- lib/decimal/decimal_test.go | 2 +- lib/decimal/decimal_timing_test.go | 8 ++-- lib/envtemplate/envtemplate.go | 2 +- lib/fastnum/fastnum.go | 4 +- lib/fastnum/fastnum_test.go | 12 +++--- lib/flagutil/password_test.go | 8 ++-- lib/ingestserver/graphite/server.go | 2 +- lib/ingestserver/influx/server.go | 2 +- lib/ingestserver/opentsdb/server.go | 2 +- lib/leveledbytebufferpool/pool.go | 2 +- lib/leveledbytebufferpool/pool_test.go | 4 +- lib/lrucache/lrucache_test.go | 2 +- lib/netutil/statdial.go | 2 +- lib/prompb/prompb_timing_test.go | 2 +- lib/promrelabel/graphite.go | 7 +++- lib/promrelabel/if_expression_timing_test.go | 2 +- lib/promrelabel/relabel_test.go | 4 +- lib/promutil/labelscompressor_test.go | 6 +-- .../opentelemetry/stream/streamparser_test.go | 2 +- .../stream/streamparser_timing_test.go | 6 +-- lib/protoparser/prometheus/parser.go | 2 +- lib/querytracer/tracer.go | 2 +- lib/querytracer/tracer_test.go | 4 +- lib/stringsutil/stringsutil.go | 2 +- lib/tenantmetrics/counter_map_test.go | 6 +-- lib/tenantmetrics/counter_map_timing_test.go | 2 +- lib/uint64set/uint64set_test.go | 42 +++++++++---------- lib/uint64set/uint64set_timing_test.go | 10 ++--- lib/workingsetcache/cache_synctest_test.go | 4 +- 46 files changed, 122 insertions(+), 119 deletions(-) diff --git a/lib/atomicutil/slice_test.go b/lib/atomicutil/slice_test.go index 4c086e1236..f7c2574dc2 100644 --- a/lib/atomicutil/slice_test.go +++ b/lib/atomicutil/slice_test.go @@ -20,7 +20,7 @@ func TestSlice_NoInit(t *testing.T) { var wg sync.WaitGroup for workerID := range workersCount { wg.Go(func() { - for i := 0; i < loopsPerWorker; i++ { + for i := range loopsPerWorker { bb := s.Get(uint(workerID)) fmt.Fprintf(bb, "item %d at worker %d\n", i, workerID) } @@ -31,7 +31,7 @@ func TestSlice_NoInit(t *testing.T) { bbs = s.All() for workerID := range workersCount { var bbExpected bytes.Buffer - for i := 0; i < loopsPerWorker; i++ { + for i := range loopsPerWorker { fmt.Fprintf(&bbExpected, "item %d at worker %d\n", i, workerID) } bb := bbs[workerID] @@ -61,7 +61,7 @@ func TestSlice_Init(t *testing.T) { var wg sync.WaitGroup for workerID := range workersCount { wg.Go(func() { - for i := 0; i < loopsPerWorker; i++ { + for i := range loopsPerWorker { bb := s.Get(uint(workerID)) fmt.Fprintf(bb, "item %d at worker %d\n", i, workerID) } @@ -72,7 +72,7 @@ func TestSlice_Init(t *testing.T) { bbs = s.All() for workerID := range workersCount { bbExpected := bytes.NewBufferString(prefix) - for i := 0; i < loopsPerWorker; i++ { + for i := range loopsPerWorker { fmt.Fprintf(bbExpected, "item %d at worker %d\n", i, workerID) } bb := bbs[workerID] diff --git a/lib/atomicutil/slice_timing_test.go b/lib/atomicutil/slice_timing_test.go index 312cdd231d..635561f9c5 100644 --- a/lib/atomicutil/slice_timing_test.go +++ b/lib/atomicutil/slice_timing_test.go @@ -19,7 +19,7 @@ func BenchmarkSlice(b *testing.B) { workerID := uint(workerIDSource.Add(1) - 1) for pb.Next() { p := s.Get(workerID) - for i := 0; i < loops; i++ { + for i := range loops { *p += i } } @@ -51,7 +51,7 @@ func BenchmarkStandardSlice_Prealloc(b *testing.B) { workerID := uint(workerIDSource.Add(1) - 1) for pb.Next() { p := s[workerID] - for i := 0; i < loops; i++ { + for i := range loops { *p += i } } @@ -79,7 +79,7 @@ func BenchmarkStandardSlice_PerCPUAlloc(b *testing.B) { s[workerID] = new(int) for pb.Next() { p := s[workerID] - for i := 0; i < loops; i++ { + for i := range loops { *p += i } } diff --git a/lib/backup/actions/util.go b/lib/backup/actions/util.go index 96ffbaaad8..d838dfb02c 100644 --- a/lib/backup/actions/util.go +++ b/lib/backup/actions/util.go @@ -94,7 +94,7 @@ func runParallelPerPathInternal(ctx context.Context, concurrency int, perPath ma // Read results. var err error - for i := 0; i < len(perPath); i++ { + for range len(perPath) { err = <-resultCh if err != nil { // Stop the work. @@ -145,7 +145,7 @@ func runParallelInternal(concurrency int, parts []common.Part, f func(p common.P // Read results. var err error - for i := 0; i < len(parts); i++ { + for range parts { err = <-resultCh if err != nil { // Stop the work. diff --git a/lib/blockcache/blockcache_test.go b/lib/blockcache/blockcache_test.go index c5b26c94a3..d446936a5b 100644 --- a/lib/blockcache/blockcache_test.go +++ b/lib/blockcache/blockcache_test.go @@ -83,7 +83,7 @@ func TestCache(t *testing.T) { if n := c.Misses(); n != 2 { t.Fatalf("unexpected number of misses; got %d; want %d", n, 2) } - for i := 0; i < *missesBeforeCaching; i++ { + for i := range *missesBeforeCaching { // Store the missed entry to the cache. It shouldn't be stored because of the previous cache miss c.TryPutBlock(k, &b) if n := c.SizeBytes(); n != 0 { @@ -142,7 +142,7 @@ func TestCacheConcurrentAccess(_ *testing.T) { } func testCacheSetGet(c *Cache, worker int) { - for i := 0; i < 1000; i++ { + for i := range 1000 { part := (any)(i) b := testBlock{} k := Key{ diff --git a/lib/blockcache/blockcache_timing_test.go b/lib/blockcache/blockcache_timing_test.go index d481238cff..65e316dc3d 100644 --- a/lib/blockcache/blockcache_timing_test.go +++ b/lib/blockcache/blockcache_timing_test.go @@ -29,7 +29,7 @@ func BenchmarkCacheGet(b *testing.B) { defer c.MustStop() const blocksCount = 10000 blocks := make([]*testBlock, blocksCount) - for i := 0; i < blocksCount; i++ { + for i := range blocksCount { blocks[i] = &testBlock{} c.TryPutBlock(Key{Offset: uint64(i)}, blocks[i]) } @@ -38,7 +38,7 @@ func BenchmarkCacheGet(b *testing.B) { b.RunParallel(func(pb *testing.PB) { var k Key for pb.Next() { - for i := 0; i < blocksCount; i++ { + for i := range blocksCount { k.Offset = uint64(i) b := c.GetBlock(k) if b != blocks[i] { diff --git a/lib/bloomfilter/filter.go b/lib/bloomfilter/filter.go index 314a7eca96..e80103c74d 100644 --- a/lib/bloomfilter/filter.go +++ b/lib/bloomfilter/filter.go @@ -42,7 +42,7 @@ func (f *filter) Has(h uint64) bool { maxBits := uint64(len(bits)) * 64 bp := (*[8]byte)(unsafe.Pointer(&h)) b := bp[:] - for i := 0; i < hashesCount; i++ { + for range hashesCount { hi := xxhash.Sum64(b) h++ idx := hi % maxBits @@ -69,7 +69,7 @@ func (f *filter) Add(h uint64) bool { bp := (*[8]byte)(unsafe.Pointer(&h)) b := bp[:] isNew := false - for i := 0; i < hashesCount; i++ { + for range hashesCount { hi := xxhash.Sum64(b) h++ idx := hi % maxBits diff --git a/lib/bloomfilter/filter_test.go b/lib/bloomfilter/filter_test.go index 1ba86c723b..7291dab640 100644 --- a/lib/bloomfilter/filter_test.go +++ b/lib/bloomfilter/filter_test.go @@ -20,7 +20,7 @@ func testFilter(t *testing.T, maxItems int) { // Populate f with maxItems collisions := 0 - for i := 0; i < maxItems; i++ { + for i := range maxItems { h := r.Uint64() items[h] = struct{}{} if !f.Add(h) { @@ -64,7 +64,7 @@ func testFilter(t *testing.T, maxItems int) { // Check filter reset f.Reset() - for i := 0; i < maxItems; i++ { + for range maxItems { h := r.Uint64() if f.Has(h) { t.Fatalf("unexpected item found in empty filter: %d", h) @@ -77,10 +77,10 @@ func TestFilterConcurrent(t *testing.T) { maxItems := 10000 doneCh := make(chan struct{}, concurrency) f := newFilter(maxItems) - for i := 0; i < concurrency; i++ { + for i := range concurrency { go func(randSeed int) { r := rand.New(rand.NewSource(int64(randSeed))) - for i := 0; i < maxItems; i++ { + for range maxItems { h := r.Uint64() f.Add(h) if !f.Has(h) { @@ -91,7 +91,7 @@ func TestFilterConcurrent(t *testing.T) { }(i) } tC := time.After(time.Second * 5) - for i := 0; i < concurrency; i++ { + for range concurrency { select { case <-doneCh: case <-tC: diff --git a/lib/bloomfilter/filter_timing_test.go b/lib/bloomfilter/filter_timing_test.go index 3c3d121484..248c33a515 100644 --- a/lib/bloomfilter/filter_timing_test.go +++ b/lib/bloomfilter/filter_timing_test.go @@ -19,7 +19,7 @@ func benchmarkFilterAdd(b *testing.B, maxItems int) { f := newFilter(maxItems) for pb.Next() { h := uint64(0) - for i := 0; i < 10000; i++ { + for range 10000 { h += uint64(maxItems) f.Add(h) } @@ -41,13 +41,13 @@ func benchmarkFilterHasHit(b *testing.B, maxItems int) { b.RunParallel(func(pb *testing.PB) { f := newFilter(maxItems) h := uint64(0) - for i := 0; i < 10000; i++ { + for range 10000 { h += uint64(maxItems) f.Add(h) } for pb.Next() { h = 0 - for i := 0; i < 10000; i++ { + for range 10000 { h += uint64(maxItems) if !f.Has(h) { panic(fmt.Errorf("missing item %d", h)) @@ -71,7 +71,7 @@ func benchmarkFilterHasMiss(b *testing.B, maxItems int) { f := newFilter(maxItems) for pb.Next() { h := uint64(0) - for i := 0; i < 10000; i++ { + for range 10000 { h += uint64(maxItems) if f.Has(h) { panic(fmt.Errorf("unexpected item %d", h)) diff --git a/lib/bloomfilter/limiter_test.go b/lib/bloomfilter/limiter_test.go index 4da8292a1a..272578a421 100644 --- a/lib/bloomfilter/limiter_test.go +++ b/lib/bloomfilter/limiter_test.go @@ -22,7 +22,7 @@ func testLimiter(t *testing.T, maxItems int) { items := make(map[uint64]struct{}, maxItems) // Populate the l with new items. - for i := 0; i < maxItems; i++ { + for i := range maxItems { h := r.Uint64() if !l.Add(h) { t.Fatalf("cannot add item %d on iteration %d out of %d", h, i, maxItems) @@ -41,7 +41,7 @@ func testLimiter(t *testing.T, maxItems int) { // Verify that new items are rejected with high probability. falseAdditions := 0 - for i := 0; i < maxItems; i++ { + for range maxItems { h := r.Uint64() if l.Add(h) { falseAdditions++ @@ -58,13 +58,13 @@ func TestLimiterConcurrent(t *testing.T) { maxItems := 10000 l := NewLimiter(maxItems, time.Hour) doneCh := make(chan struct{}, concurrency) - for i := 0; i < concurrency; i++ { + for range concurrency { go func() { if n := l.MaxItems(); n != maxItems { panic(fmt.Errorf("unexpected maxItems returned; got %d; want %d", n, maxItems)) } r := rand.New(rand.NewSource(0)) - for i := 0; i < maxItems; i++ { + for range maxItems { h := r.Uint64() // Do not check whether the item is added, since less than maxItems can be added to l // due to passible (expected) race in l.f.Add @@ -72,7 +72,7 @@ func TestLimiterConcurrent(t *testing.T) { } // Verify that new items are rejected with high probability. falseAdditions := 0 - for i := 0; i < maxItems; i++ { + for range maxItems { h := r.Uint64() if l.Add(h) { falseAdditions++ @@ -86,7 +86,7 @@ func TestLimiterConcurrent(t *testing.T) { }() } tC := time.After(time.Second * 5) - for i := 0; i < concurrency; i++ { + for range concurrency { select { case <-doneCh: case <-tC: diff --git a/lib/bytesutil/bytesutil_test.go b/lib/bytesutil/bytesutil_test.go index 7e52bd33a8..341ccbee46 100644 --- a/lib/bytesutil/bytesutil_test.go +++ b/lib/bytesutil/bytesutil_test.go @@ -31,7 +31,7 @@ func TestRoundToNearestPow2(t *testing.T) { } func TestResizeNoCopyNoOverallocate(t *testing.T) { - for i := 0; i < 1000; i++ { + for i := range 1000 { b := ResizeNoCopyNoOverallocate(nil, i) if len(b) != i { t.Fatalf("invalid b size; got %d; want %d", len(b), i) @@ -73,7 +73,7 @@ func TestResizeNoCopyNoOverallocate(t *testing.T) { } func TestResizeNoCopyMayOverallocate(t *testing.T) { - for i := 0; i < 1000; i++ { + for i := range 1000 { b := ResizeNoCopyMayOverallocate(nil, i) if len(b) != i { t.Fatalf("invalid b size; got %d; want %d", len(b), i) @@ -110,7 +110,7 @@ func TestResizeNoCopyMayOverallocate(t *testing.T) { } func TestResizeWithCopyNoOverallocate(t *testing.T) { - for i := 0; i < 1000; i++ { + for i := range 1000 { b := ResizeWithCopyNoOverallocate(nil, i) if len(b) != i { t.Fatalf("invalid b size; got %d; want %d", len(b), i) @@ -152,7 +152,7 @@ func TestResizeWithCopyNoOverallocate(t *testing.T) { } func TestResizeWithCopyMayOverallocate(t *testing.T) { - for i := 0; i < 1000; i++ { + for i := range 1000 { b := ResizeWithCopyMayOverallocate(nil, i) if len(b) != i { t.Fatalf("invalid b size; got %d; want %d", len(b), i) diff --git a/lib/bytesutil/fast_string_matcher_test.go b/lib/bytesutil/fast_string_matcher_test.go index 3643f75475..6b5e718edd 100644 --- a/lib/bytesutil/fast_string_matcher_test.go +++ b/lib/bytesutil/fast_string_matcher_test.go @@ -12,7 +12,7 @@ func TestFastStringMatcher(t *testing.T) { }) f := func(s string, resultExpected bool) { t.Helper() - for i := 0; i < 10; i++ { + for i := range 10 { result := fsm.Match(s) if result != resultExpected { t.Fatalf("unexpected result for Match(%q) at iteration %d; got %v; want %v", s, i, result, resultExpected) diff --git a/lib/bytesutil/fast_string_transformer_test.go b/lib/bytesutil/fast_string_transformer_test.go index 62d002914e..79f161ccbd 100644 --- a/lib/bytesutil/fast_string_transformer_test.go +++ b/lib/bytesutil/fast_string_transformer_test.go @@ -9,7 +9,7 @@ func TestFastStringTransformer(t *testing.T) { fst := NewFastStringTransformer(strings.ToUpper) f := func(s, resultExpected string) { t.Helper() - for i := 0; i < 10; i++ { + for i := range 10 { result := fst.Transform(s) if result != resultExpected { t.Fatalf("unexpected result for Transform(%q) at iteration %d; got %q; want %q", s, i, result, resultExpected) diff --git a/lib/bytesutil/internstring_test.go b/lib/bytesutil/internstring_test.go index 0d352e78d5..c432a1f7e1 100644 --- a/lib/bytesutil/internstring_test.go +++ b/lib/bytesutil/internstring_test.go @@ -15,13 +15,13 @@ func TestInternStringSerial(t *testing.T) { func TestInternStringConcurrent(t *testing.T) { concurrency := 5 resultCh := make(chan error, concurrency) - for i := 0; i < concurrency; i++ { + for range concurrency { go func() { resultCh <- testInternString() }() } timer := time.NewTimer(5 * time.Second) - for i := 0; i < concurrency; i++ { + for range concurrency { select { case err := <-resultCh: if err != nil { @@ -34,7 +34,7 @@ func TestInternStringConcurrent(t *testing.T) { } func testInternString() error { - for i := 0; i < 1000; i++ { + for i := range 1000 { s := fmt.Sprintf("foo_%d", i) s1 := InternString(s) if s != s1 { diff --git a/lib/bytesutil/itoa_test.go b/lib/bytesutil/itoa_test.go index 4a2fb48ed8..cff3fa74ee 100644 --- a/lib/bytesutil/itoa_test.go +++ b/lib/bytesutil/itoa_test.go @@ -7,7 +7,7 @@ import ( func TestItoa(t *testing.T) { f := func(n int, resultExpected string) { t.Helper() - for i := 0; i < 5; i++ { + for range 5 { result := Itoa(n) if result != resultExpected { t.Fatalf("unexpected result for Itoa(%d); got %q; want %q", n, result, resultExpected) diff --git a/lib/chunkedbuffer/buffer_test.go b/lib/chunkedbuffer/buffer_test.go index 91c2b20646..f84297bcaf 100644 --- a/lib/chunkedbuffer/buffer_test.go +++ b/lib/chunkedbuffer/buffer_test.go @@ -11,7 +11,7 @@ func TestBuffer(t *testing.T) { cb := Get() defer Put(cb) - for i := 0; i < 10; i++ { + for range 10 { cb.Reset() // Write data to chunked buffer diff --git a/lib/consistenthash/consistent_hash_test.go b/lib/consistenthash/consistent_hash_test.go index 0af8c6a660..275b592169 100644 --- a/lib/consistenthash/consistent_hash_test.go +++ b/lib/consistenthash/consistent_hash_test.go @@ -18,7 +18,7 @@ func TestConsistentHash(t *testing.T) { rh := NewConsistentHash(nodes, 0) keys := make([]uint64, 100000) - for i := 0; i < len(keys); i++ { + for i := range keys { keys[i] = r.Uint64() } perIdxCounts := make([]int, len(nodes)) diff --git a/lib/consistenthash/consistent_hash_timing_test.go b/lib/consistenthash/consistent_hash_timing_test.go index d5394ffdd2..ebcbd9bc36 100644 --- a/lib/consistenthash/consistent_hash_timing_test.go +++ b/lib/consistenthash/consistent_hash_timing_test.go @@ -31,7 +31,7 @@ func BenchmarkConsistentHash(b *testing.B) { var benchKeys = func() []uint64 { r := rand.New(rand.NewSource(1)) keys := make([]uint64, 10000) - for i := 0; i < len(keys); i++ { + for i := range keys { keys[i] = r.Uint64() } return keys diff --git a/lib/decimal/decimal_test.go b/lib/decimal/decimal_test.go index 04bf2860b7..1067a1160d 100644 --- a/lib/decimal/decimal_test.go +++ b/lib/decimal/decimal_test.go @@ -507,7 +507,7 @@ func TestFloatToDecimalRoundtrip(t *testing.T) { f(vStaleNaN) r := rand.New(rand.NewSource(1)) - for i := 0; i < 1e4; i++ { + for range int(1e4) { v := r.NormFloat64() f(v) f(v * 1e-6) diff --git a/lib/decimal/decimal_timing_test.go b/lib/decimal/decimal_timing_test.go index 061a18ef34..7b104a2dc8 100644 --- a/lib/decimal/decimal_timing_test.go +++ b/lib/decimal/decimal_timing_test.go @@ -59,7 +59,7 @@ func benchmarkAppendDecimalToFloat(b *testing.B, a []int64, scale int16) { var testZeros = make([]int64, 8*1024) var testOnes = func() []int64 { a := make([]int64, 8*1024) - for i := 0; i < len(a); i++ { + for i := range a { a[i] = 1 } return a @@ -83,7 +83,7 @@ func BenchmarkAppendFloatToDecimal(b *testing.B) { var testFZeros = make([]float64, 8*1024) var testFOnes = func() []float64 { a := make([]float64, 8*1024) - for i := 0; i < len(a); i++ { + for i := range a { a[i] = 1 } return a @@ -108,7 +108,7 @@ func benchmarkAppendFloatToDecimal(b *testing.B, fa []float64) { var testFAReal = func() []float64 { r := rand.New(rand.NewSource(1)) fa := make([]float64, 8*1024) - for i := 0; i < len(fa); i++ { + for i := range fa { fa[i] = r.NormFloat64() * 1e-6 } return fa @@ -117,7 +117,7 @@ var testFAReal = func() []float64 { var testFAInteger = func() []float64 { r := rand.New(rand.NewSource(2)) fa := make([]float64, 8*1024) - for i := 0; i < len(fa); i++ { + for i := range fa { fa[i] = float64(int(r.NormFloat64() * 1e6)) } return fa diff --git a/lib/envtemplate/envtemplate.go b/lib/envtemplate/envtemplate.go index ac632bd0a0..0d8b8294c3 100644 --- a/lib/envtemplate/envtemplate.go +++ b/lib/envtemplate/envtemplate.go @@ -53,7 +53,7 @@ func parseEnvVars(envs []string) map[string]string { } func expandTemplates(m map[string]string) map[string]string { - for i := 0; i < len(m); i++ { + for range len(m) { mExpanded := make(map[string]string, len(m)) expands := 0 for name, value := range m { diff --git a/lib/fastnum/fastnum.go b/lib/fastnum/fastnum.go index 34966947b4..b2d232cfa7 100644 --- a/lib/fastnum/fastnum.go +++ b/lib/fastnum/fastnum.go @@ -134,7 +134,7 @@ func float64ToByteSlice(a []float64) []byte { var ( int64Zeros [8 * 1024]int64 int64Ones = func() (a [8 * 1024]int64) { - for i := 0; i < len(a); i++ { + for i := range len(a) { a[i] = 1 } return a @@ -142,7 +142,7 @@ var ( float64Zeros [8 * 1024]float64 float64Ones = func() (a [8 * 1024]float64) { - for i := 0; i < len(a); i++ { + for i := range len(a) { a[i] = 1 } return a diff --git a/lib/fastnum/fastnum_test.go b/lib/fastnum/fastnum_test.go index ddb514a29d..565e17666f 100644 --- a/lib/fastnum/fastnum_test.go +++ b/lib/fastnum/fastnum_test.go @@ -26,7 +26,7 @@ func TestIsInt64Ones(t *testing.T) { for _, n := range []int{0, 1, 10, 100, 1000, 1e4, 1e5, 8*1024 + 1} { t.Run(fmt.Sprintf("%d_items", n), func(t *testing.T) { a := make([]int64, n) - for i := 0; i < n; i++ { + for i := range n { a[i] = 1 } if !IsInt64Ones(a) { @@ -63,7 +63,7 @@ func TestIsFloat64Ones(t *testing.T) { for _, n := range []int{0, 1, 10, 100, 1000, 1e4, 1e5, 8*1024 + 1} { t.Run(fmt.Sprintf("%d_items", n), func(t *testing.T) { a := make([]float64, n) - for i := 0; i < n; i++ { + for i := range n { a[i] = 1 } if !IsFloat64Ones(a) { @@ -95,7 +95,7 @@ func TestAppendInt64Zeros(t *testing.T) { if len(a) != len(prefix)+n { t.Fatalf("unexpected len(a) with prefix; got %d; want %d", len(a), len(prefix)+n) } - for i := 0; i < len(prefix); i++ { + for i := range prefix { if a[i] != prefix[i] { t.Fatalf("unexpected prefix[%d]; got %d; want %d", i, a[i], prefix[i]) } @@ -123,7 +123,7 @@ func TestAppendInt64Ones(t *testing.T) { if len(a) != len(prefix)+n { t.Fatalf("unexpected len(a) with prefix; got %d; want %d", len(a), len(prefix)+n) } - for i := 0; i < len(prefix); i++ { + for i := range prefix { if a[i] != prefix[i] { t.Fatalf("unexpected prefix[%d]; got %d; want %d", i, a[i], prefix[i]) } @@ -151,7 +151,7 @@ func TestAppendFloat64Zeros(t *testing.T) { if len(a) != len(prefix)+n { t.Fatalf("unexpected len(a) with prefix; got %d; want %d", len(a), len(prefix)+n) } - for i := 0; i < len(prefix); i++ { + for i := range prefix { if a[i] != prefix[i] { t.Fatalf("unexpected prefix[%d]; got %f; want %f", i, a[i], prefix[i]) } @@ -179,7 +179,7 @@ func TestAppendFloat64Ones(t *testing.T) { if len(a) != len(prefix)+n { t.Fatalf("unexpected len(a) with prefix; got %d; want %d", len(a), len(prefix)+n) } - for i := 0; i < len(prefix); i++ { + for i := range prefix { if a[i] != prefix[i] { t.Fatalf("unexpected prefix[%d]; got %f; want %f", i, a[i], prefix[i]) } diff --git a/lib/flagutil/password_test.go b/lib/flagutil/password_test.go index 8a9583406f..1fb1d490a2 100644 --- a/lib/flagutil/password_test.go +++ b/lib/flagutil/password_test.go @@ -21,7 +21,7 @@ func TestPassword(t *testing.T) { if err := p.Set(expectedPassword); err != nil { t.Fatalf("cannot set password: %s", err) } - for i := 0; i < 5; i++ { + for range 5 { if s := p.Get(); s != expectedPassword { t.Fatalf("unexpected password; got %q; want %q", s, expectedPassword) } @@ -37,7 +37,7 @@ func TestPassword(t *testing.T) { if err := p.Set(path); err != nil { t.Fatalf("cannot set password to file: %s", err) } - for i := 0; i < 5; i++ { + for range 5 { if s := p.Get(); s != expectedPassword { t.Fatalf("unexpected password; got %q; want %q", s, expectedPassword) } @@ -57,7 +57,7 @@ func TestPassword(t *testing.T) { if err := p.Set(path); err != nil { t.Fatalf("unexpected error: %s", err) } - for i := 0; i < 5; i++ { + for range 5 { if s := p.Get(); s != expectedPassword { t.Fatalf("unexpected password; got %q; want %q", s, expectedPassword) } @@ -70,7 +70,7 @@ func TestPassword(t *testing.T) { if err := p.Set("http://127.0.0.1:56283/aaa/bb?cc=dd"); err != nil { t.Fatalf("unexpected error: %s", err) } - for i := 0; i < 5; i++ { + for range 5 { if s := p.Get(); len(s) != 64 { t.Fatalf("unexpected password obtained: %q; must be random 64-byte password", s) } diff --git a/lib/ingestserver/graphite/server.go b/lib/ingestserver/graphite/server.go index 3f5063d6a9..7073a2b05c 100644 --- a/lib/ingestserver/graphite/server.go +++ b/lib/ingestserver/graphite/server.go @@ -132,7 +132,7 @@ func (s *Server) serveTCP(insertHandler func(r io.Reader) error) { func (s *Server) serveUDP(insertHandler func(r io.Reader) error) { gomaxprocs := cgroup.AvailableCPUs() var wg sync.WaitGroup - for i := 0; i < gomaxprocs; i++ { + for range gomaxprocs { wg.Go(func() { var bb bytesutil.ByteBuffer bb.B = bytesutil.ResizeNoCopyNoOverallocate(bb.B, 64*1024) diff --git a/lib/ingestserver/influx/server.go b/lib/ingestserver/influx/server.go index e7afb85930..2ed9cb33ef 100644 --- a/lib/ingestserver/influx/server.go +++ b/lib/ingestserver/influx/server.go @@ -130,7 +130,7 @@ func (s *Server) serveTCP(insertHandler func(r io.Reader) error) { func (s *Server) serveUDP(insertHandler func(r io.Reader) error) { gomaxprocs := cgroup.AvailableCPUs() var wg sync.WaitGroup - for i := 0; i < gomaxprocs; i++ { + for range gomaxprocs { wg.Go(func() { var bb bytesutil.ByteBuffer bb.B = bytesutil.ResizeNoCopyNoOverallocate(bb.B, 64*1024) diff --git a/lib/ingestserver/opentsdb/server.go b/lib/ingestserver/opentsdb/server.go index 5ec960fab9..5c4dc0c0b3 100644 --- a/lib/ingestserver/opentsdb/server.go +++ b/lib/ingestserver/opentsdb/server.go @@ -147,7 +147,7 @@ func (s *Server) serveTelnet(ln net.Listener, insertHandler func(r io.Reader) er func (s *Server) serveUDP(insertHandler func(r io.Reader) error) { gomaxprocs := cgroup.AvailableCPUs() var wg sync.WaitGroup - for i := 0; i < gomaxprocs; i++ { + for range gomaxprocs { wg.Go(func() { var bb bytesutil.ByteBuffer bb.B = bytesutil.ResizeNoCopyNoOverallocate(bb.B, 64*1024) diff --git a/lib/leveledbytebufferpool/pool.go b/lib/leveledbytebufferpool/pool.go index ebe691539c..a5579d3a9f 100644 --- a/lib/leveledbytebufferpool/pool.go +++ b/lib/leveledbytebufferpool/pool.go @@ -22,7 +22,7 @@ var pools [10]sync.Pool // Get returns byte buffer, which is able to store at least dataLen bytes. func Get(dataLen int) *bytesutil.ByteBuffer { id, capacityNeeded := getPoolIDAndCapacity(dataLen) - for i := 0; i < 2; i++ { + for range 2 { if id < 0 || id >= len(pools) { break } diff --git a/lib/leveledbytebufferpool/pool_test.go b/lib/leveledbytebufferpool/pool_test.go index d1aa84ec19..f201927c9c 100644 --- a/lib/leveledbytebufferpool/pool_test.go +++ b/lib/leveledbytebufferpool/pool_test.go @@ -11,7 +11,7 @@ import ( func TestGetPutConcurrent(t *testing.T) { const concurrency = 10 doneCh := make(chan struct{}, concurrency) - for i := 0; i < concurrency; i++ { + for range concurrency { go func() { for capacity := -1; capacity < 100; capacity++ { bb := Get(capacity) @@ -28,7 +28,7 @@ func TestGetPutConcurrent(t *testing.T) { }() } tc := time.After(10 * time.Second) - for i := 0; i < concurrency; i++ { + for range concurrency { select { case <-tc: t.Fatalf("timeout") diff --git a/lib/lrucache/lrucache_test.go b/lib/lrucache/lrucache_test.go index f8481b8044..d9267189c1 100644 --- a/lib/lrucache/lrucache_test.go +++ b/lib/lrucache/lrucache_test.go @@ -137,7 +137,7 @@ func TestCacheConcurrentAccess(_ *testing.T) { } func testCacheSetGet(c *Cache, worker int) { - for i := 0; i < 1000; i++ { + for i := range 1000 { e := testEntry{} k := fmt.Sprintf("key_%d_%d", worker, i) c.PutEntry(k, &e) diff --git a/lib/netutil/statdial.go b/lib/netutil/statdial.go index aba99830b8..07f28240e5 100644 --- a/lib/netutil/statdial.go +++ b/lib/netutil/statdial.go @@ -98,7 +98,7 @@ func (sc *statDialConn) Close() error { func isTCPv4Addr(addr string) bool { s := addr - for i := 0; i < 3; i++ { + for range 3 { n := strings.IndexByte(s, '.') if n < 0 { return false diff --git a/lib/prompb/prompb_timing_test.go b/lib/prompb/prompb_timing_test.go index c60da603c6..87ae7814a0 100644 --- a/lib/prompb/prompb_timing_test.go +++ b/lib/prompb/prompb_timing_test.go @@ -33,7 +33,7 @@ func BenchmarkWriteRequestMarshalProtobuf(b *testing.B) { var benchWriteRequest = func() *WriteRequest { var tss []TimeSeries - for i := 0; i < 1_000; i++ { + for i := range 1_000 { ts := TimeSeries{ Labels: []Label{ { diff --git a/lib/promrelabel/graphite.go b/lib/promrelabel/graphite.go index 0ae63afb6d..fe840ebe4d 100644 --- a/lib/promrelabel/graphite.go +++ b/lib/promrelabel/graphite.go @@ -86,7 +86,9 @@ func (gmt *graphiteMatchTemplate) Match(dst []string, s string) ([]string, bool) return dst, false } } - for i := 0; i < len(parts); i++ { + + i := 0 + for i < len(parts) { p := parts[i] if p != "*" { if !strings.HasPrefix(s, p) { @@ -94,6 +96,7 @@ func (gmt *graphiteMatchTemplate) Match(dst []string, s string) ([]string, bool) return dst, false } s = s[len(p):] + i++ continue } // Search for the matching substring for '*' part. @@ -108,7 +111,7 @@ func (gmt *graphiteMatchTemplate) Match(dst []string, s string) ([]string, bool) } // Search for the start of the next part. p = parts[i+1] - i++ + i += 2 n := strings.Index(s, p) if n < 0 { // Cannot match the next part diff --git a/lib/promrelabel/if_expression_timing_test.go b/lib/promrelabel/if_expression_timing_test.go index b5240e6f44..24f0596cb7 100644 --- a/lib/promrelabel/if_expression_timing_test.go +++ b/lib/promrelabel/if_expression_timing_test.go @@ -11,7 +11,7 @@ import ( func BenchmarkIfExpression(b *testing.B) { const maxLabels = 100 labels := make([]prompb.Label, maxLabels) - for i := 0; i < maxLabels; i++ { + for i := range maxLabels { label := prompb.Label{ Name: fmt.Sprintf("foo%d", i), Value: fmt.Sprintf("bar%d", i), diff --git a/lib/promrelabel/relabel_test.go b/lib/promrelabel/relabel_test.go index f8a3c97839..9fb966911b 100644 --- a/lib/promrelabel/relabel_test.go +++ b/lib/promrelabel/relabel_test.go @@ -12,7 +12,7 @@ import ( func TestSanitizeMetricName(t *testing.T) { f := func(s, resultExpected string) { t.Helper() - for i := 0; i < 5; i++ { + for i := range 5 { result := SanitizeMetricName(s) if result != resultExpected { t.Fatalf("unexpected result for SanitizeMetricName(%q) at iteration %d; got %q; want %q", s, i, result, resultExpected) @@ -28,7 +28,7 @@ func TestSanitizeMetricName(t *testing.T) { func TestSanitizeLabelName(t *testing.T) { f := func(s, resultExpected string) { t.Helper() - for i := 0; i < 5; i++ { + for i := range 5 { result := SanitizeLabelName(s) if result != resultExpected { t.Fatalf("unexpected result for SanitizeLabelName(%q) at iteration %d; got %q; want %q", s, i, result, resultExpected) diff --git a/lib/promutil/labelscompressor_test.go b/lib/promutil/labelscompressor_test.go index ad20374086..9babc6b161 100644 --- a/lib/promutil/labelscompressor_test.go +++ b/lib/promutil/labelscompressor_test.go @@ -71,7 +71,7 @@ func TestLabelsCompressorConcurrent(t *testing.T) { var expectCompressedKeys sync.Map var wg sync.WaitGroup - for i := 0; i < concurrency; i++ { + for i := range concurrency { wg.Go(func() { series := newTestSeries(100, 20) for n, labels := range series { @@ -109,9 +109,9 @@ func labelsToString(labels []prompb.Label) string { func newTestSeries(seriesCount, labelsPerSeries int) [][]prompb.Label { series := make([][]prompb.Label, seriesCount) - for i := 0; i < seriesCount; i++ { + for i := range seriesCount { labels := make([]prompb.Label, labelsPerSeries) - for j := 0; j < labelsPerSeries; j++ { + for j := range labelsPerSeries { labels[j] = prompb.Label{ Name: fmt.Sprintf("label_%d", j), Value: fmt.Sprintf("value_%d_%d", i, j), diff --git a/lib/protoparser/opentelemetry/stream/streamparser_test.go b/lib/protoparser/opentelemetry/stream/streamparser_test.go index 9fdb59eee5..9fe5b63b90 100644 --- a/lib/protoparser/opentelemetry/stream/streamparser_test.go +++ b/lib/protoparser/opentelemetry/stream/streamparser_test.go @@ -32,7 +32,7 @@ func TestParseStream(t *testing.T) { return fmt.Errorf("unexpected time series count; got: %d; want: %d\ntimeseries got:\n%s\ntimeseries want\n%s", len(tss), len(tssExpected), prettifyTimeSeries(tss), prettifyTimeSeries(tssExpected)) } - for i := 0; i < len(tss); i++ { + for i := range tss { ts := tss[i] tsExpected := tssExpected[i] if len(ts.Labels) != len(tsExpected.Labels) { diff --git a/lib/protoparser/opentelemetry/stream/streamparser_timing_test.go b/lib/protoparser/opentelemetry/stream/streamparser_timing_test.go index b1809ffcf2..b13f981ee7 100644 --- a/lib/protoparser/opentelemetry/stream/streamparser_timing_test.go +++ b/lib/protoparser/opentelemetry/stream/streamparser_timing_test.go @@ -103,9 +103,9 @@ func BenchmarkWriteRequestContextPushSample(b *testing.B) { timeSeriesCount := 100000 labels := make([]*promutil.Labels, 0, timeSeriesCount) mms := make([]*pb.MetricMetadata, 0, timeSeriesCount) - for i := 0; i < timeSeriesCount; i++ { + for i := range timeSeriesCount { lbs := &promutil.Labels{} - for j := 0; j < 20; j++ { + for j := range 20 { lbs.Labels = append(lbs.Labels, prompb.Label{ Name: fmt.Sprintf("some_super_long_label_%d", j), Value: fmt.Sprintf("some_super_super_super_super_super_super_long_label_%d", j), @@ -129,7 +129,7 @@ func BenchmarkWriteRequestContextPushSample(b *testing.B) { return nil } - for i := 0; i < timeSeriesCount; i++ { + for i := range timeSeriesCount { benchmarkWriteRequestContextPushSample(b, wctx, mms[i], labels[i]) } diff --git a/lib/protoparser/prometheus/parser.go b/lib/protoparser/prometheus/parser.go index 05ed2e1599..c80a792978 100644 --- a/lib/protoparser/prometheus/parser.go +++ b/lib/protoparser/prometheus/parser.go @@ -747,7 +747,7 @@ func AreIdenticalSeriesFast(s1, s2 string) bool { } func isNumeric(s string) bool { - for i := 0; i < len(s); i++ { + for i := range len(s) { if numericChars[s[i]] { continue } diff --git a/lib/querytracer/tracer.go b/lib/querytracer/tracer.go index 38d20a8509..868bc8ae32 100644 --- a/lib/querytracer/tracer.go +++ b/lib/querytracer/tracer.go @@ -283,7 +283,7 @@ type span struct { func (s *span) writePlaintextWithIndent(w io.Writer, indent int) { prefix := "" - for i := 0; i < indent; i++ { + for range indent { prefix += "| " } prefix += "- " diff --git a/lib/querytracer/tracer_test.go b/lib/querytracer/tracer_test.go index eb1166bcd6..def74787b7 100644 --- a/lib/querytracer/tracer_test.go +++ b/lib/querytracer/tracer_test.go @@ -151,10 +151,10 @@ func TestTraceConcurrent(t *testing.T) { childLocal.Printf("abc") childLocal.Done() var wg sync.WaitGroup - for i := 0; i < 3; i++ { + for i := range 3 { child := qt.NewChild("child %d", i) wg.Go(func() { - for j := 0; j < 100; j++ { + for j := range 100 { child.Printf("message %d", j) } }) diff --git a/lib/stringsutil/stringsutil.go b/lib/stringsutil/stringsutil.go index faa5126b93..6c1fc3552d 100644 --- a/lib/stringsutil/stringsutil.go +++ b/lib/stringsutil/stringsutil.go @@ -28,7 +28,7 @@ func AppendLowercase(dst []byte, s string) []byte { // Try fast path at first by assuming that s contains only ASCII chars. hasUnicodeChars := false - for i := 0; i < len(s); i++ { + for i := range len(s) { c := s[i] if c >= utf8.RuneSelf { hasUnicodeChars = true diff --git a/lib/tenantmetrics/counter_map_test.go b/lib/tenantmetrics/counter_map_test.go index b4334537ea..925fc0afdd 100644 --- a/lib/tenantmetrics/counter_map_test.go +++ b/lib/tenantmetrics/counter_map_test.go @@ -52,7 +52,7 @@ func TestCounterMap(t *testing.T) { func TestCounterMapConcurrent(t *testing.T) { cm := NewCounterMap(`aaa{bb="cc"}`) f := func() error { - for i := 0; i < 10; i++ { + for range 10 { cm.Get(&auth.Token{AccountID: 1, ProjectID: 2}).Inc() if n := cm.Get(&auth.Token{AccountID: 3, ProjectID: 4}).Get(); n != 0 { return fmt.Errorf("unexpected counter value; got %d; want %d", n, 0) @@ -64,13 +64,13 @@ func TestCounterMapConcurrent(t *testing.T) { const concurrency = 5 ch := make(chan error, concurrency) - for i := 0; i < concurrency; i++ { + for range concurrency { go func() { ch <- f() }() } - for i := 0; i < concurrency; i++ { + for range concurrency { select { case err := <-ch: if err != nil { diff --git a/lib/tenantmetrics/counter_map_timing_test.go b/lib/tenantmetrics/counter_map_timing_test.go index 4e16482158..2b86395c07 100644 --- a/lib/tenantmetrics/counter_map_timing_test.go +++ b/lib/tenantmetrics/counter_map_timing_test.go @@ -12,7 +12,7 @@ func BenchmarkCounterMapGrowth(b *testing.B) { f := func(b *testing.B, numTenants uint32, nProcs int) { b.Helper() - for i := 0; i < b.N; i++ { + for range b.N { cm := NewCounterMap("foobar") var wg sync.WaitGroup for range nProcs { diff --git a/lib/uint64set/uint64set_test.go b/lib/uint64set/uint64set_test.go index e546015f57..34639901e3 100644 --- a/lib/uint64set/uint64set_test.go +++ b/lib/uint64set/uint64set_test.go @@ -162,7 +162,7 @@ func TestSetOps(t *testing.T) { f([]uint64{0, 2 << 32}, []uint64{1 << 32, 2 << 32, 3 << 32}) var a []uint64 - for i := 0; i < 100; i++ { + for i := range 100 { a = append(a, uint64(i)) } var b []uint64 @@ -180,10 +180,10 @@ func TestSetOps(t *testing.T) { f(a, b) r := rand.New(rand.NewSource(1)) - for i := 0; i < 10; i++ { + for range 10 { a = nil b = nil - for j := 0; j < 1000; j++ { + for range 1000 { a = append(a, uint64(r.Intn(1e6))) b = append(b, uint64(r.Intn(1e6))) } @@ -283,7 +283,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { // Verify forward Add itemsCount = (itemsCount / 2) * 2 - for i := 0; i < itemsCount/2; i++ { + for i := range itemsCount / 2 { s.Add(uint64(i) + offset) } if n := s.Len(); n != itemsCount/2 { @@ -294,7 +294,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { } // Verify backward Add - for i := 0; i < itemsCount/2; i++ { + for i := range itemsCount / 2 { s.Add(uint64(itemsCount-i-1) + offset) } if n := s.Len(); n != itemsCount { @@ -302,7 +302,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { } // Verify repeated Add - for i := 0; i < itemsCount/2; i++ { + for i := range itemsCount / 2 { s.Add(uint64(i) + offset) } if n := s.Len(); n != itemsCount { @@ -310,7 +310,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { } // Verify Has on existing bits - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { if !s.Has(uint64(i) + offset) { t.Fatalf("missing bit %d", uint64(i)+offset) } @@ -328,7 +328,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { if n := sCopy.Len(); n != itemsCount { t.Fatalf("unexpected sCopy.Len(); got %d; want %d", n, itemsCount) } - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { if !sCopy.Has(uint64(i) + offset) { t.Fatalf("missing bit %d on sCopy", uint64(i)+offset) } @@ -373,7 +373,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { for _, x := range a { m[x] = true } - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { if !m[uint64(i)+offset] { t.Fatalf("missing bit %d in the exported bits; array:\n%d", uint64(i)+offset, a) } @@ -383,7 +383,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { { var s Set m := make(map[uint64]bool) - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { v := uint64(i) + offset s.Add(v) m[v] = true @@ -425,7 +425,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { { const unionOffset = 12345 var s1, s2 Set - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { s1.Add(uint64(i) + offset) s2.Add(uint64(i) + offset + unionOffset) } @@ -457,7 +457,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { { const unionOffset = 12345 var s1, s2 Set - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { s1.Add(uint64(i) + offset) s2.Add(uint64(i) + offset + unionOffset) } @@ -492,7 +492,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { for _, intersectOffset := range []uint64{123, 12345, 1<<32 + 4343} { s1 = Set{} s2 = Set{} - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { s1.Add(uint64(i) + offset) s2.Add(uint64(i) + offset + intersectOffset) } @@ -529,7 +529,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { { const subtractOffset = 12345 var s1, s2 Set - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { s1.Add(uint64(i) + offset) s2.Add(uint64(i) + offset + subtractOffset) } @@ -568,7 +568,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { for _, x := range a { m[x] = true } - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { if i >= itemsCount/2 && i < itemsCount-itemsCount/4 { if m[uint64(i)+offset] { t.Fatalf("unexpected bit found after deleting: %d", uint64(i)+offset) @@ -594,7 +594,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) { if n := sCopy.Len(); n != itemsCount { t.Fatalf("unexpected sCopy.Len(); got %d; want %d", n, itemsCount) } - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { if !sCopy.Has(uint64(i) + offset) { t.Fatalf("missing bit %d on sCopy", uint64(i)+offset) } @@ -613,7 +613,7 @@ func testSetSparseItems(t *testing.T, itemsCount int) { r := rand.New(rand.NewSource(1)) var s Set m := make(map[uint64]bool) - for i := 0; i < itemsCount; i++ { + for range itemsCount { x := r.Uint64() s.Add(x) m[x] = true @@ -631,7 +631,7 @@ func testSetSparseItems(t *testing.T, itemsCount int) { t.Fatalf("missing item %d", x) } } - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { x := uint64(i) if m[x] { continue @@ -743,19 +743,19 @@ func TestAddMulti(t *testing.T) { f([]uint64{0, 1 << 16, 2 << 16, 2<<16 + 1, 1 << 32, 2 << 32, 2<<32 + 1}) var a []uint64 - for i := 0; i < 32000; i++ { + for i := range 32000 { a = append(a, uint64(i)) } f(a) a = nil - for i := 0; i < 32000; i++ { + for i := range 32000 { a = append(a, 1<<16+uint64(i)) } f(a) a = nil - for i := 0; i < 100000; i++ { + for i := range 100000 { a = append(a, 1<<32+uint64(i)) } f(a) diff --git a/lib/uint64set/uint64set_timing_test.go b/lib/uint64set/uint64set_timing_test.go index 203ac6f9ba..7cfd55e85a 100644 --- a/lib/uint64set/uint64set_timing_test.go +++ b/lib/uint64set/uint64set_timing_test.go @@ -216,7 +216,7 @@ func BenchmarkSubtract(b *testing.B) { func createRangeSet(start uint64, itemsCount int) *Set { var s Set - for i := 0; i < itemsCount; i++ { + for i := range itemsCount { n := start + uint64(i) s.Add(n) } @@ -235,7 +235,7 @@ func BenchmarkSetAddRandomLastBits(b *testing.B) { for pb.Next() { start := uint64(time.Now().UnixNano()) var s Set - for i := 0; i < itemsCount; i++ { + for range int(itemsCount) { n := start | (uint64(rng.Uint32()) & mask) s.Add(n) } @@ -257,7 +257,7 @@ func BenchmarkMapAddRandomLastBits(b *testing.B) { for pb.Next() { start := uint64(time.Now().UnixNano()) m := make(map[uint64]struct{}) - for i := 0; i < itemsCount; i++ { + for range int(itemsCount) { n := start | (uint64(rng.Uint32()) & mask) m[n] = struct{}{} } @@ -362,7 +362,7 @@ func BenchmarkSetHasHitRandomLastBits(b *testing.B) { start := uint64(time.Now().UnixNano()) var s Set var rng fastrand.RNG - for i := 0; i < itemsCount; i++ { + for range int(itemsCount) { n := start | (uint64(rng.Uint32()) & mask) s.Add(n) } @@ -392,7 +392,7 @@ func BenchmarkMapHasHitRandomLastBits(b *testing.B) { start := uint64(time.Now().UnixNano()) m := make(map[uint64]struct{}) var rng fastrand.RNG - for i := 0; i < itemsCount; i++ { + for range int(itemsCount) { n := start | (uint64(rng.Uint32()) & mask) m[n] = struct{}{} } diff --git a/lib/workingsetcache/cache_synctest_test.go b/lib/workingsetcache/cache_synctest_test.go index b6d4d905b0..c9063311ce 100644 --- a/lib/workingsetcache/cache_synctest_test.go +++ b/lib/workingsetcache/cache_synctest_test.go @@ -271,7 +271,7 @@ func testSetBigGetBigStatsInSplitMode(t *testing.T, c *Cache) { v := func(seed, size int) []byte { var buf []byte - for i := 0; i < size; i++ { + for i := range size { buf = append(buf, byte(i+seed)) } return buf @@ -530,7 +530,7 @@ func TestSetBigGetBigStatsInWholeMode_cacheLoadedFromNonEmptyFile(t *testing.T) synctest.Test(t, func(t *testing.T) { v := func(seed, size int) []byte { var buf []byte - for i := 0; i < size; i++ { + for i := range size { buf = append(buf, byte(i+seed)) } return buf