diff --git a/pkg/coordinator/worker_test.go b/pkg/coordinator/worker_test.go index a08b8b71..fe4f7a1a 100644 --- a/pkg/coordinator/worker_test.go +++ b/pkg/coordinator/worker_test.go @@ -82,7 +82,7 @@ func testUnReserveConcurrent(t *testing.T) { atomic.StoreInt32((*int32)(&s), int32(workers)) wg.Add(workers) - for i := 0; i < workers; i++ { + for range workers { go func() { defer wg.Done() s.UnReserve() @@ -126,7 +126,7 @@ func testTryReserveConcurrent(t *testing.T) { var wg sync.WaitGroup wg.Add(workers) - for i := 0; i < workers; i++ { + for range workers { go func() { defer wg.Done() if s.TryReserve() { diff --git a/pkg/encoder/color/rgba/rgba.go b/pkg/encoder/color/rgba/rgba.go index c37d6218..5bb2e9bc 100644 --- a/pkg/encoder/color/rgba/rgba.go +++ b/pkg/encoder/color/rgba/rgba.go @@ -9,12 +9,12 @@ func ToRGBA(img image.Image, flipped bool) *image.RGBA { bounds := img.Bounds() sw, sh := bounds.Dx(), bounds.Dy() dst := image.NewRGBA(image.Rect(0, 0, sw, sh)) - for y := 0; y < sh; y++ { + for y := range sh { yy := y if flipped { yy = sh - y } - for x := 0; x < sw; x++ { + for x := range sw { px := img.At(x, y) rgba := color.RGBAModel.Convert(px).(color.RGBA) dst.Set(x, yy, rgba) diff --git a/pkg/encoder/h264/x264_test.go b/pkg/encoder/h264/x264_test.go index 0fe1bb43..822e4cec 100644 --- a/pkg/encoder/h264/x264_test.go +++ b/pkg/encoder/h264/x264_test.go @@ -23,7 +23,7 @@ func Benchmark(b *testing.B) { return } data := make([]byte, int(float64(w)*float64(h)*1.5)) - for i := 0; i < b.N; i++ { + for b.Loop() { h264.Encode(data) } } diff --git a/pkg/encoder/yuv/yuv_test.go b/pkg/encoder/yuv/yuv_test.go index e4e74b30..4e0ebbf7 100644 --- a/pkg/encoder/yuv/yuv_test.go +++ b/pkg/encoder/yuv/yuv_test.go @@ -123,7 +123,7 @@ func TestYuvPredefined(t *testing.T) { t.Fatalf("different size a: %v, o: %v", len(a), len(should)) } - for i := 0; i < len(a); i++ { + for i := range a { if a[i] != should[i] { t.Fatalf("diff in %vth, %v != %v \n%v\n%v", i, a[i], should[i], im, should) } @@ -188,8 +188,8 @@ func BenchmarkYuv(b *testing.B) { func genFrame(w, h int, seed float32) RawFrame { img := image.NewRGBA(image.Rectangle{Max: image.Point{X: w, Y: h}}) - for x := 0; x < w; x++ { - for y := 0; y < h; y++ { + for x := range w { + for y := range h { col := color.RGBA{R: uint8(seed * 255), G: uint8(seed * 255), B: uint8(seed * 255), A: 0xff} img.Set(x, y, col) } @@ -217,9 +217,9 @@ func TestGen24bitFull(t *testing.T) { // radius = centerY //} - for y := 0; y < wh; y++ { + for y := range wh { dy := float64(y - centerY) - for x := 0; x < wh; x++ { + for x := range wh { dx := float64(x - centerX) dist := math.Sqrt(dx*dx + dy*dy) if dist <= float64(radius) { diff --git a/pkg/games/library_test.go b/pkg/games/library_test.go index dc85fbbf..28975647 100644 --- a/pkg/games/library_test.go +++ b/pkg/games/library_test.go @@ -117,7 +117,7 @@ func Benchmark(b *testing.B) { Supported: []string{"gba", "zip", "nes"}, }, config.Emulator{}, log) - for range b.N { + for b.Loop() { library.Scan() _ = library.GetAll() } diff --git a/pkg/resampler/simple.go b/pkg/resampler/simple.go index f2859a3e..39e509c0 100644 --- a/pkg/resampler/simple.go +++ b/pkg/resampler/simple.go @@ -10,7 +10,7 @@ func Linear(dst, src []int16) { // replicate single pair input or output if srcPairs == 1 || dstPairs == 1 { - for i := 0; i < dstPairs; i++ { + for i := range dstPairs { dst[i*2], dst[i*2+1] = src[0], src[1] } return @@ -46,7 +46,7 @@ func Nearest(dst, src []int16) { srcPairs, dstPairs := nSrc>>1, nDst>>1 if srcPairs == 1 || dstPairs == 1 { - for i := 0; i < dstPairs; i++ { + for i := range dstPairs { dst[i*2], dst[i*2+1] = src[0], src[1] } return diff --git a/pkg/worker/caged/libretro/frontend_test.go b/pkg/worker/caged/libretro/frontend_test.go index fda0ecbe..2cacd5a4 100644 --- a/pkg/worker/caged/libretro/frontend_test.go +++ b/pkg/worker/caged/libretro/frontend_test.go @@ -329,8 +329,7 @@ func TestStateConcurrency(t *testing.T) { qLock.Unlock() if lucky() && !lucky() { - ops.Add(1) - go func() { + ops.Go(func() { qLock.Lock() defer qLock.Unlock() @@ -344,8 +343,7 @@ func TestStateConcurrency(t *testing.T) { if snapshot1 != snapshot2 { t.Errorf("States are inconsistent %v != %v on tick %v\n", snapshot1, snapshot2, i+1) } - ops.Done() - }() + }) } } diff --git a/pkg/worker/caged/libretro/nanoarch/input_test.go b/pkg/worker/caged/libretro/nanoarch/input_test.go index 4921df59..042d108e 100644 --- a/pkg/worker/caged/libretro/nanoarch/input_test.go +++ b/pkg/worker/caged/libretro/nanoarch/input_test.go @@ -13,7 +13,7 @@ func TestConcurrentInput(t *testing.T) { events := 1000 wg.Add(2 * events) - for i := 0; i < events; i++ { + for range events { player := rand.Intn(maxPort) go func() { state.Input(player, []byte{0, 1}); wg.Done() }() go func() { state.IsKeyPressed(uint(player), 100); wg.Done() }() diff --git a/pkg/worker/media/buffer_test.go b/pkg/worker/media/buffer_test.go index a2be89d8..6c8d300a 100644 --- a/pkg/worker/media/buffer_test.go +++ b/pkg/worker/media/buffer_test.go @@ -26,7 +26,7 @@ func samplesOf(v int16, n int) samples { func ramp(pairs int) samples { s := make(samples, pairs*2) - for i := 0; i < pairs; i++ { + for i := range pairs { s[i*2], s[i*2+1] = int16(i), int16(i) } return s diff --git a/pkg/worker/media/media_test.go b/pkg/worker/media/media_test.go index 3e264e80..a0fd9399 100644 --- a/pkg/worker/media/media_test.go +++ b/pkg/worker/media/media_test.go @@ -79,7 +79,7 @@ func run(w, h int, cod encoder.VideoCodec, count int, a *image.RGBA, b *image.RG b = genTestImage(w, h, rand.Float32()) } - for i := 0; i < count; i++ { + for i := range count { im := a if i%2 == 0 { im = b @@ -98,8 +98,8 @@ func run(w, h int, cod encoder.VideoCodec, count int, a *image.RGBA, b *image.RG func genTestImage(w, h int, seed float32) *image.RGBA { img := image.NewRGBA(image.Rectangle{Max: image.Point{X: w, Y: h}}) - for x := 0; x < w; x++ { - for y := 0; y < h; y++ { + for x := range w { + for y := range h { i := img.PixOffset(x, y) s := img.Pix[i : i+4 : i+4] s[0] = uint8(seed * 255) diff --git a/pkg/worker/recorder/recorder_test.go b/pkg/worker/recorder/recorder_test.go index fcfe1f57..d968cc34 100644 --- a/pkg/worker/recorder/recorder_test.go +++ b/pkg/worker/recorder/recorder_test.go @@ -46,7 +46,7 @@ func TestName(t *testing.T) { audioWg.Add(iterations) frame := genFrame(100, 100) - for i := 0; i < 222; i++ { + for range 222 { go func() { recorder.WriteVideo(Video{Frame: frame, Duration: 16 * time.Millisecond}) imgWg.Done() @@ -134,8 +134,8 @@ func benchmarkRecorder(w, h int, b *testing.B) { func genFrame(w, h int) Frame { img := image.NewRGBA(image.Rect(0, 0, w, h)) - for x := 0; x < w; x++ { - for y := 0; y < h; y++ { + for x := range w { + for y := range h { img.Set(x, y, randomColor()) } }