aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/pprof
diff options
context:
space:
mode:
authorGyu-Ho Lee <gyuhox@gmail.com>2016-06-04 23:20:45 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2016-10-12 06:33:34 +0000
commit456b7f5a974f229e0ef7ad5a1925fa72fc4182e2 (patch)
tree8da10d84f3379265d44842b9bae27bd909049c15 /src/runtime/pprof
parent81b9af7cccce8234319551330cb6406469f32bab (diff)
downloadgo-456b7f5a974f229e0ef7ad5a1925fa72fc4182e2.tar.xz
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>
Diffstat (limited to 'src/runtime/pprof')
-rw-r--r--src/runtime/pprof/pprof.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go
index b4dd1c4173..9fd477908c 100644
--- a/src/runtime/pprof/pprof.go
+++ b/src/runtime/pprof/pprof.go
@@ -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)