Skip to content

Commit

Permalink
Use for range
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Apr 22, 2024
1 parent b755bcd commit b3f677d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
3 changes: 1 addition & 2 deletions pkg/com/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func TestMap_Base(t *testing.T) {

func TestMap_Concurrency(t *testing.T) {
m := Map[int, int]{m: make(map[int]int)}
for i := 0; i < 100; i++ {
i := i
for i := range 100 {
go m.Put(i, i)
go m.Has(i)
go m.Pop(i)
Expand Down
5 changes: 2 additions & 3 deletions pkg/com/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ func testWebsocket(t *testing.T) {

// test
for _, call := range calls {
call := call
if call.concurrent {
for i := 0; i < n; i++ {
for range n {
packet := call.packet
go func() {
defer wait.Done()
Expand All @@ -104,7 +103,7 @@ func testWebsocket(t *testing.T) {
}()
}
} else {
for i := 0; i < n; i++ {
for range n {
packet := call.packet
vv, err := client.rpc.Call(client.sock.conn, &packet)
err = checkCall(vv, err, call.value)
Expand Down
2 changes: 1 addition & 1 deletion pkg/games/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Benchmark(b *testing.B) {
Supported: []string{"gba", "zip", "nes"},
}, config.Emulator{}, log)

for i := 0; i < b.N; i++ {
for range b.N {
library.Scan()
_ = library.GetAll()
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/worker/caged/libretro/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func BenchmarkEmulators(b *testing.B) {
for _, bench := range benchmarks {
b.Run(bench.name, func(b *testing.B) {
s := DefaultFrontend("bench_"+bench.system+"_performance", bench.system, bench.rom)
for i := 0; i < b.N; i++ {
for range b.N {
s.nano.Run()
}
s.Shutdown()
Expand Down Expand Up @@ -294,12 +294,11 @@ func TestStateConcurrency(t *testing.T) {

_ = mock.Save()

for i := 0; i < test.run.frames; i++ {
for i := range test.run.frames {
qLock.Lock()
mock.Tick()
qLock.Unlock()

i := i
if lucky() && !lucky() {
ops.Add(1)
go func() {
Expand Down Expand Up @@ -332,7 +331,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.setInput(player, []byte{0, 1}); wg.Done() }()
go func() { state.isKeyPressed(uint(player), 100); wg.Done() }()
Expand Down
4 changes: 2 additions & 2 deletions pkg/worker/caged/libretro/nanoarch/nanoarch.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (n *Nanoarch) LoadGame(path string) error {

// set default controller types on all ports
// needed for nestopia
for i := 0; i < MaxPort; i++ {
for i := range MaxPort {
C.bridge_retro_set_controller_port_device(retroSetControllerPortDevice, C.uint(i), C.RETRO_DEVICE_JOYPAD)
}

Expand Down Expand Up @@ -774,7 +774,7 @@ func coreEnvironment(cmd C.unsigned, data unsafe.Pointer) C.bool {
cd := (*[32]C.struct_retro_controller_description)(tp)
delim := ", "
n := int(controller.num_types)
for i := 0; i < n; i++ {
for i := range n {
if i == n-1 {
delim = ""
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/worker/caged/libretro/nanoarch/nanoarch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func TestLimit(t *testing.T) {
c := atomic.Int32{}
lim := NewLimit(50 * time.Millisecond)

for i := 0; i < 10; i++ {
for range 10 {
lim(func() {
c.Add(1)
})
Expand Down

0 comments on commit b3f677d

Please sign in to comment.