1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:04:57 -07:00

runtime/pprof: preallocate slice in pprof.go

To prevent slice growth when appending.

Change-Id: I2cdb9b09bc33f63188b19573c8b9a77601e63801
Reviewed-on: https://go-review.googlesource.com/23783
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Gyu-Ho Lee 2016-06-04 23:20:45 -07:00 committed by Brad Fitzpatrick
parent 81b9af7ccc
commit 456b7f5a97

View File

@ -202,7 +202,7 @@ func Profiles() []*Profile {
lockProfiles()
defer unlockProfiles()
var all []*Profile
all := make([]*Profile, 0, len(profiles.m))
for _, p := range profiles.m {
all = append(all, p)
}
@ -293,7 +293,7 @@ func (p *Profile) WriteTo(w io.Writer, debug int) error {
}
// Obtain consistent snapshot under lock; then process without lock.
var all [][]uintptr
all := make([][]uintptr, 0, len(p.m))
p.mu.Lock()
for _, stk := range p.m {
all = append(all, stk)