From 020a18c545bf49ffc087ca93cd238195d8dcc411 Mon Sep 17 00:00:00 2001 From: Martin Möhrmann Date: Sun, 14 Oct 2018 22:28:58 +0200 Subject: cmd/compile: move slice construction to callers of makeslice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Gobot Gobot Reviewed-by: Josh Bleecher Snyder --- src/runtime/slice.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/runtime/slice.go') 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() -- cgit v1.3-5-g45d5