Skip to content

Iterate over pointers instead of copies.

Ariejan de Vroom requested to merge github/fork/marcopeereboom/broken_range into master

Created by: marcopeereboom

Modify addressable to become a pointer because Go's range does not provide a pointer to the element but a copy of the element (urgh).

Go's range operator really can be considered broken. In this case it copies the addressable all the time which significantly slows things down. To boot, it isn't writing in the memory you think it is (it ends up in the copy of memory).

Before the change:

$ go test -v -test.run Klaus
=== RUN TestKlausDormann6502
Running Klaus Dormann' 6502 functional tests. This may take some time...
Klaus Dormann's 6502 functional tests passed.
--- PASS: TestKlausDormann6502 (13.51s)
PASS
ok      github.com/ariejan/i6502        13.522s

After the change:

$ go test -v -test.run Klaus
=== RUN TestKlausDormann6502
Running Klaus Dormann' 6502 functional tests. This may take some time...
Klaus Dormann's 6502 functional tests passed.
--- PASS: TestKlausDormann6502 (4.87s)
PASS
ok      github.com/ariejan/i6502        4.877s

Merge request reports