]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: clean up some silly allp loops
authorAustin Clements <austin@google.com>
Tue, 13 Jun 2017 14:33:24 +0000 (10:33 -0400)
committerAustin Clements <austin@google.com>
Tue, 13 Jun 2017 18:57:48 +0000 (18:57 +0000)
Back in the day, allp was just a pointer to an array. As a result, the
runtime has a few loops of the form:

    for i := 0; ; i++ {
        p := allp[i]
if p == nil {
    break
}
...
    }

This is silly now because it requires that allp be one longer than the
maximum possible number of Ps, but now that allp is in Go it has a
length.

Replace these with range loops.

Change-Id: I91ef4bc7bd3c9d4fda2264f4aa1b1d0271d7f578
Reviewed-on: https://go-review.googlesource.com/45571
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/mstats.go
src/runtime/proc.go

index 849e01860b051a6936f6fa77f9413aeb9413be4f..1cb44a15ddb3e9dfd8a684cb7bd67ef6d5b0c9e1 100644 (file)
@@ -591,8 +591,7 @@ func updatememstats() {
 
 //go:nowritebarrier
 func cachestats() {
-       for i := 0; ; i++ {
-               p := allp[i]
+       for _, p := range &allp {
                if p == nil {
                        break
                }
index 099605fe5291b90d362f25d50b6765dcdbb7eb09..afedf19aedf189db28efd068d53de3d5401bb2c5 100644 (file)
@@ -3158,8 +3158,7 @@ func badunlockosthread() {
 
 func gcount() int32 {
        n := int32(allglen) - sched.ngfree - int32(atomic.Load(&sched.ngsys))
-       for i := 0; ; i++ {
-               _p_ := allp[i]
+       for _, _p_ := range &allp {
                if _p_ == nil {
                        break
                }