Use for range

This commit is contained in:
Sergey Stepanov 2024-04-22 17:46:13 +03:00 committed by sergystepanov
parent b755bcd1bf
commit b3f677d32f
6 changed files with 10 additions and 13 deletions

View file

@ -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)

View file

@ -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()
@ -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)

View file

@ -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()
}

View file

@ -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()
@ -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() {
@ -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() }()

View file

@ -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)
}
@ -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 = ""
}

View file

@ -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)
})