aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/slice.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2016-04-19 15:14:26 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2016-04-20 00:05:36 +0000
commit0150f15a924a7b4ac0c794012f6b12c8aa406b54 (patch)
treece022ac8a79549faf47f16d84bc86784fd4e0066 /src/runtime/slice.go
parent7b0ba1cff86429f0eb39b916fba54e3061fa5787 (diff)
downloadgo-0150f15a924a7b4ac0c794012f6b12c8aa406b54.tar.gz
go-0150f15a924a7b4ac0c794012f6b12c8aa406b54.zip
runtime: call mallocgc directly from makeslice and growslice
The extra checks provided by newarray are redundant in these cases. This shrinks by one frame the call stack expected by the pprof test. name old time/op new time/op delta MakeSlice-8 34.3ns ± 2% 30.5ns ± 3% -11.03% (p=0.000 n=24+22) GrowSlicePtr-8 134ns ± 2% 129ns ± 3% -3.25% (p=0.000 n=25+24) Change-Id: Icd828655906b921c732701fd9d61da3fa217b0af Reviewed-on: https://go-review.googlesource.com/22276 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/slice.go')
-rw-r--r--src/runtime/slice.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index f9414d7658..873e97ebff 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -55,7 +55,12 @@ func makeslice(t *slicetype, len64, cap64 int64) slice {
panic(errorString("makeslice: cap out of range"))
}
- p := newarray(t.elem, uintptr(cap))
+ et := t.elem
+ var flags uint32
+ if et.kind&kindNoPointers != 0 {
+ flags = flagNoScan
+ }
+ p := mallocgc(et.size*uintptr(cap), et, flags)
return slice{p, len, cap}
}
@@ -130,7 +135,7 @@ func growslice(t *slicetype, old slice, cap int) slice {
memclr(add(p, lenmem), capmem-lenmem)
} else {
// Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan uninitialized memory.
- p = newarray(et, uintptr(newcap))
+ p = mallocgc(capmem, et, 0)
if !writeBarrier.enabled {
memmove(p, old.array, lenmem)
} else {