From 200d0cc1929daa6331b552989b43d186d410d983 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 13 Jun 2017 10:33:24 -0400 Subject: [PATCH] runtime: clean up some silly allp loops 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/runtime/mstats.go | 3 +-- src/runtime/proc.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go index 849e01860b0..1cb44a15ddb 100644 --- a/src/runtime/mstats.go +++ b/src/runtime/mstats.go @@ -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 } diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 099605fe529..afedf19aedf 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -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 }