aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/slice.go
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2018-10-14 22:28:58 +0200
committerMartin Möhrmann <martisch@uos.de>2018-10-29 19:23:00 +0000
commit020a18c545bf49ffc087ca93cd238195d8dcc411 (patch)
tree0d9aba99dc40be4eb38f00a7a2a8c6cef93cee8f /src/runtime/slice.go
parentc86d4647348b420f55d4ce7572c4cd93b20a1d4a (diff)
downloadgo-020a18c545bf49ffc087ca93cd238195d8dcc411.tar.gz
go-020a18c545bf49ffc087ca93cd238195d8dcc411.zip
cmd/compile: move slice construction to callers of makeslice
Only return a pointer p to the new slices backing array from makeslice. Makeslice callers then construct sliceheader{p, len, cap} explictly instead of makeslice returning the slice. Reduces go binary size by ~0.2%. Removes 92 (~3.5%) panicindex calls from go binary. Change-Id: I29b7c3b5fe8b9dcec96e2c43730575071cfe8a94 Reviewed-on: https://go-review.googlesource.com/c/141822 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'src/runtime/slice.go')
-rw-r--r--src/runtime/slice.go7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index 9a081043b0..2309b1a615 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -31,7 +31,7 @@ func panicmakeslicecap() {
panic(errorString("makeslice: cap out of range"))
}
-func makeslice(et *_type, len, cap int) slice {
+func makeslice(et *_type, len, cap int) unsafe.Pointer {
mem, overflow := math.MulUintptr(et.size, uintptr(cap))
if overflow || mem > maxAlloc || len < 0 || len > cap {
// NOTE: Produce a 'len out of range' error instead of a
@@ -45,12 +45,11 @@ func makeslice(et *_type, len, cap int) slice {
}
panicmakeslicecap()
}
- p := mallocgc(mem, et, true)
- return slice{p, len, cap}
+ return mallocgc(mem, et, true)
}
-func makeslice64(et *_type, len64, cap64 int64) slice {
+func makeslice64(et *_type, len64, cap64 int64) unsafe.Pointer {
len := int(len64)
if int64(len) != len64 {
panicmakeslicelen()