Skip to content

Commit cef9ae9

Browse files
committed
run go fix -rangeint
1 parent f608073 commit cef9ae9

File tree

7 files changed

+55
-55
lines changed

7 files changed

+55
-55
lines changed

bigcache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestSetGetBig(t *testing.T) {
1111
const valuesCount = 10
1212
for _, valueSize := range []int{1, 100, 1<<16 - 1, 1 << 16, 1<<16 + 1, 1 << 17, 1<<17 + 1, 1<<17 - 1, 1 << 19} {
1313
t.Run(fmt.Sprintf("valueSize_%d", valueSize), func(t *testing.T) {
14-
for seed := 0; seed < 3; seed++ {
14+
for seed := range 3 {
1515
testSetGetBig(t, c, valueSize, valuesCount, seed)
1616
}
1717
})
@@ -21,7 +21,7 @@ func TestSetGetBig(t *testing.T) {
2121
func testSetGetBig(t *testing.T, c *Cache, valueSize, valuesCount, seed int) {
2222
m := make(map[string][]byte)
2323
var buf []byte
24-
for i := 0; i < valuesCount; i++ {
24+
for i := range valuesCount {
2525
key := []byte(fmt.Sprintf("key %d", i))
2626
value := createValue(valueSize, seed)
2727
c.SetBig(key, value)
@@ -51,7 +51,7 @@ func testSetGetBig(t *testing.T, c *Cache, valueSize, valuesCount, seed int) {
5151

5252
func createValue(size, seed int) []byte {
5353
var buf []byte
54-
for i := 0; i < size; i++ {
54+
for i := range size {
5555
buf = append(buf, byte(i+seed))
5656
}
5757
return buf

fastcache_gen_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestGenerationOverflow(t *testing.T) {
2828
}
2929

3030
// Do some initial Set/Get demonstrate that this works
31-
for i := 0; i < 10; i++ {
31+
for i := range 10 {
3232
c.Set(key1, bigVal1)
3333
c.Set(key2, bigVal2)
3434
getVal(t, c, key1, bigVal1)
@@ -76,7 +76,7 @@ func TestGenerationOverflow(t *testing.T) {
7676
getVal(t, c, key2, bigVal2)
7777

7878
// Do it a few more times to show that this bucket is now unusable
79-
for i := 0; i < 10; i++ {
79+
for i := range 10 {
8080
c.Set(key1, bigVal1)
8181
c.Set(key2, bigVal2)
8282
getVal(t, c, key1, bigVal1)

fastcache_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestCacheWrap(t *testing.T) {
7474

7575
calls := uint64(5e6)
7676

77-
for i := uint64(0); i < calls; i++ {
77+
for i := range calls {
7878
k := []byte(fmt.Sprintf("key %d", i))
7979
v := []byte(fmt.Sprintf("value %d", i))
8080
c.Set(k, v)
@@ -83,7 +83,7 @@ func TestCacheWrap(t *testing.T) {
8383
t.Fatalf("unexpected value for key %q; got %q; want %q", k, vv, v)
8484
}
8585
}
86-
for i := uint64(0); i < calls/10; i++ {
86+
for i := range calls / 10 {
8787
x := i * 10
8888
k := []byte(fmt.Sprintf("key %d", x))
8989
v := []byte(fmt.Sprintf("value %d", x))
@@ -122,7 +122,7 @@ func TestCacheWrap(t *testing.T) {
122122
func TestCacheDel(t *testing.T) {
123123
c := New(1024)
124124
defer c.Reset()
125-
for i := 0; i < 100; i++ {
125+
for i := range 100 {
126126
k := []byte(fmt.Sprintf("key %d", i))
127127
v := []byte(fmt.Sprintf("value %d", i))
128128
c.Set(k, v)
@@ -177,12 +177,12 @@ func TestCacheGetSetConcurrent(t *testing.T) {
177177
defer c.Reset()
178178

179179
ch := make(chan error, gorotines)
180-
for i := 0; i < gorotines; i++ {
180+
for range gorotines {
181181
go func() {
182182
ch <- testCacheGetSet(c, itemsCount)
183183
}()
184184
}
185-
for i := 0; i < gorotines; i++ {
185+
for range gorotines {
186186
select {
187187
case err := <-ch:
188188
if err != nil {
@@ -195,7 +195,7 @@ func TestCacheGetSetConcurrent(t *testing.T) {
195195
}
196196

197197
func testCacheGetSet(c *Cache, itemsCount int) error {
198-
for i := 0; i < itemsCount; i++ {
198+
for i := range itemsCount {
199199
k := []byte(fmt.Sprintf("key %d", i))
200200
v := []byte(fmt.Sprintf("value %d", i))
201201
c.Set(k, v)
@@ -205,7 +205,7 @@ func testCacheGetSet(c *Cache, itemsCount int) error {
205205
}
206206
}
207207
misses := 0
208-
for i := 0; i < itemsCount; i++ {
208+
for i := range itemsCount {
209209
k := []byte(fmt.Sprintf("key %d", i))
210210
vExpected := fmt.Sprintf("value %d", i)
211211
v := c.Get(nil, k)
@@ -229,7 +229,7 @@ func TestCacheResetUpdateStatsSetConcurrent(t *testing.T) {
229229

230230
// run workers for cache reset
231231
var resettersWG sync.WaitGroup
232-
for i := 0; i < 10; i++ {
232+
for range 10 {
233233
resettersWG.Add(1)
234234
go func() {
235235
defer resettersWG.Done()
@@ -247,7 +247,7 @@ func TestCacheResetUpdateStatsSetConcurrent(t *testing.T) {
247247

248248
// run workers for update cache stats
249249
var statsWG sync.WaitGroup
250-
for i := 0; i < 10; i++ {
250+
for range 10 {
251251
statsWG.Add(1)
252252
go func() {
253253
defer statsWG.Done()
@@ -266,11 +266,11 @@ func TestCacheResetUpdateStatsSetConcurrent(t *testing.T) {
266266

267267
// run workers for setting data to cache
268268
var settersWG sync.WaitGroup
269-
for i := 0; i < 10; i++ {
269+
for range 10 {
270270
settersWG.Add(1)
271271
go func() {
272272
defer settersWG.Done()
273-
for j := 0; j < 100; j++ {
273+
for j := range 100 {
274274
key := []byte(fmt.Sprintf("key_%d", j))
275275
value := []byte(fmt.Sprintf("value_%d", j))
276276
c.Set(key, value)

fastcache_timing_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func BenchmarkBigCacheSet(b *testing.B) {
2525
k := []byte("\x00\x00\x00\x00")
2626
v := []byte("xyza")
2727
for pb.Next() {
28-
for i := 0; i < items; i++ {
28+
for range items {
2929
k[0]++
3030
if k[0] == 0 {
3131
k[1]++
@@ -49,7 +49,7 @@ func BenchmarkBigCacheGet(b *testing.B) {
4949
defer c.Close()
5050
k := []byte("\x00\x00\x00\x00")
5151
v := []byte("xyza")
52-
for i := 0; i < items; i++ {
52+
for range items {
5353
k[0]++
5454
if k[0] == 0 {
5555
k[1]++
@@ -64,7 +64,7 @@ func BenchmarkBigCacheGet(b *testing.B) {
6464
b.RunParallel(func(pb *testing.PB) {
6565
k := []byte("\x00\x00\x00\x00")
6666
for pb.Next() {
67-
for i := 0; i < items; i++ {
67+
for range items {
6868
k[0]++
6969
if k[0] == 0 {
7070
k[1]++
@@ -96,7 +96,7 @@ func BenchmarkBigCacheSetGet(b *testing.B) {
9696
k := []byte("\x00\x00\x00\x00")
9797
v := []byte("xyza")
9898
for pb.Next() {
99-
for i := 0; i < items; i++ {
99+
for range items {
100100
k[0]++
101101
if k[0] == 0 {
102102
k[1]++
@@ -105,7 +105,7 @@ func BenchmarkBigCacheSetGet(b *testing.B) {
105105
panic(fmt.Errorf("unexpected error: %s", err))
106106
}
107107
}
108-
for i := 0; i < items; i++ {
108+
for range items {
109109
k[0]++
110110
if k[0] == 0 {
111111
k[1]++
@@ -136,7 +136,7 @@ func BenchmarkCacheSet(b *testing.B) {
136136
k := []byte("\x00\x00\x00\x00")
137137
v := []byte("xyza")
138138
for pb.Next() {
139-
for i := 0; i < items; i++ {
139+
for range items {
140140
k[0]++
141141
if k[0] == 0 {
142142
k[1]++
@@ -153,7 +153,7 @@ func BenchmarkCacheGet(b *testing.B) {
153153
defer c.Reset()
154154
k := []byte("\x00\x00\x00\x00")
155155
v := []byte("xyza")
156-
for i := 0; i < items; i++ {
156+
for range items {
157157
k[0]++
158158
if k[0] == 0 {
159159
k[1]++
@@ -167,7 +167,7 @@ func BenchmarkCacheGet(b *testing.B) {
167167
var buf []byte
168168
k := []byte("\x00\x00\x00\x00")
169169
for pb.Next() {
170-
for i := 0; i < items; i++ {
170+
for range items {
171171
k[0]++
172172
if k[0] == 0 {
173173
k[1]++
@@ -186,7 +186,7 @@ func BenchmarkCacheHas(b *testing.B) {
186186
c := New(12 * items)
187187
defer c.Reset()
188188
k := []byte("\x00\x00\x00\x00")
189-
for i := 0; i < items; i++ {
189+
for range items {
190190
k[0]++
191191
if k[0] == 0 {
192192
k[1]++
@@ -199,7 +199,7 @@ func BenchmarkCacheHas(b *testing.B) {
199199
b.RunParallel(func(pb *testing.PB) {
200200
k := []byte("\x00\x00\x00\x00")
201201
for pb.Next() {
202-
for i := 0; i < items; i++ {
202+
for range items {
203203
k[0]++
204204
if k[0] == 0 {
205205
k[1]++
@@ -223,14 +223,14 @@ func BenchmarkCacheSetGet(b *testing.B) {
223223
v := []byte("xyza")
224224
var buf []byte
225225
for pb.Next() {
226-
for i := 0; i < items; i++ {
226+
for range items {
227227
k[0]++
228228
if k[0] == 0 {
229229
k[1]++
230230
}
231231
c.Set(k, v)
232232
}
233-
for i := 0; i < items; i++ {
233+
for range items {
234234
k[0]++
235235
if k[0] == 0 {
236236
k[1]++
@@ -254,7 +254,7 @@ func BenchmarkStdMapSet(b *testing.B) {
254254
k := []byte("\x00\x00\x00\x00")
255255
v := []byte("xyza")
256256
for pb.Next() {
257-
for i := 0; i < items; i++ {
257+
for range items {
258258
k[0]++
259259
if k[0] == 0 {
260260
k[1]++
@@ -272,7 +272,7 @@ func BenchmarkStdMapGet(b *testing.B) {
272272
m := make(map[string][]byte)
273273
k := []byte("\x00\x00\x00\x00")
274274
v := []byte("xyza")
275-
for i := 0; i < items; i++ {
275+
for range items {
276276
k[0]++
277277
if k[0] == 0 {
278278
k[1]++
@@ -286,7 +286,7 @@ func BenchmarkStdMapGet(b *testing.B) {
286286
b.RunParallel(func(pb *testing.PB) {
287287
k := []byte("\x00\x00\x00\x00")
288288
for pb.Next() {
289-
for i := 0; i < items; i++ {
289+
for range items {
290290
k[0]++
291291
if k[0] == 0 {
292292
k[1]++
@@ -312,7 +312,7 @@ func BenchmarkStdMapSetGet(b *testing.B) {
312312
k := []byte("\x00\x00\x00\x00")
313313
v := []byte("xyza")
314314
for pb.Next() {
315-
for i := 0; i < items; i++ {
315+
for range items {
316316
k[0]++
317317
if k[0] == 0 {
318318
k[1]++
@@ -321,7 +321,7 @@ func BenchmarkStdMapSetGet(b *testing.B) {
321321
m[string(k)] = v
322322
mu.Unlock()
323323
}
324-
for i := 0; i < items; i++ {
324+
for range items {
325325
k[0]++
326326
if k[0] == 0 {
327327
k[1]++
@@ -346,7 +346,7 @@ func BenchmarkSyncMapSet(b *testing.B) {
346346
k := []byte("\x00\x00\x00\x00")
347347
v := "xyza"
348348
for pb.Next() {
349-
for i := 0; i < items; i++ {
349+
for range items {
350350
k[0]++
351351
if k[0] == 0 {
352352
k[1]++
@@ -362,7 +362,7 @@ func BenchmarkSyncMapGet(b *testing.B) {
362362
m := sync.Map{}
363363
k := []byte("\x00\x00\x00\x00")
364364
v := "xyza"
365-
for i := 0; i < items; i++ {
365+
for range items {
366366
k[0]++
367367
if k[0] == 0 {
368368
k[1]++
@@ -375,7 +375,7 @@ func BenchmarkSyncMapGet(b *testing.B) {
375375
b.RunParallel(func(pb *testing.PB) {
376376
k := []byte("\x00\x00\x00\x00")
377377
for pb.Next() {
378-
for i := 0; i < items; i++ {
378+
for range items {
379379
k[0]++
380380
if k[0] == 0 {
381381
k[1]++
@@ -398,14 +398,14 @@ func BenchmarkSyncMapSetGet(b *testing.B) {
398398
k := []byte("\x00\x00\x00\x00")
399399
v := "xyza"
400400
for pb.Next() {
401-
for i := 0; i < items; i++ {
401+
for range items {
402402
k[0]++
403403
if k[0] == 0 {
404404
k[1]++
405405
}
406406
m.Store(string(k), v)
407407
}
408-
for i := 0; i < items; i++ {
408+
for range items {
409409
k[0]++
410410
if k[0] == 0 {
411411
k[1]++

file.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (c *Cache) save(dir string, workersCount int) error {
113113
// Save buckets by workersCount concurrent workers.
114114
workCh := make(chan int, workersCount)
115115
results := make(chan error)
116-
for i := 0; i < workersCount; i++ {
116+
for i := range workersCount {
117117
go func(workerNum int) {
118118
results <- saveBuckets(c.buckets[:], workCh, dir, workerNum)
119119
}(i)
@@ -126,7 +126,7 @@ func (c *Cache) save(dir string, workersCount int) error {
126126

127127
// Read results.
128128
var err error
129-
for i := 0; i < workersCount; i++ {
129+
for range workersCount {
130130
result := <-results
131131
if result != nil && err == nil {
132132
err = result
@@ -174,7 +174,7 @@ func load(filePath string, maxBytes int) (*Cache, error) {
174174
}(filePath + "/" + fn)
175175
}
176176
err = nil
177-
for i := 0; i < workersCount; i++ {
177+
for range workersCount {
178178
result := <-results
179179
if result != nil && err == nil {
180180
err = result
@@ -326,7 +326,7 @@ func (b *bucket) Save(w io.Writer) error {
326326
if err := writeUint64(w, uint64(chunksLen)); err != nil {
327327
return fmt.Errorf("cannot write len(b.chunks): %s", err)
328328
}
329-
for chunkIdx := 0; chunkIdx < chunksLen; chunkIdx++ {
329+
for chunkIdx := range chunksLen {
330330
chunk := b.chunks[chunkIdx][:chunkSize]
331331
if _, err := w.Write(chunk); err != nil {
332332
return fmt.Errorf("cannot write b.chunks[%d]: %s", chunkIdx, err)
@@ -382,7 +382,7 @@ func (b *bucket) Load(r io.Reader, maxChunks uint64) error {
382382
if currChunkIdx > 0 && currChunkIdx >= chunksLen {
383383
return fmt.Errorf("too big bIdx=%d; should be smaller than %d", bIdx, chunksLen*chunkSize)
384384
}
385-
for chunkIdx := uint64(0); chunkIdx < chunksLen; chunkIdx++ {
385+
for chunkIdx := range chunksLen {
386386
chunk := getChunk()
387387
chunks[chunkIdx] = chunk
388388
if _, err := io.ReadFull(r, chunk); err != nil {

0 commit comments

Comments
 (0)