aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/slice.go
diff options
context:
space:
mode:
authorMartin Möhrmann <martisch@uos.de>2016-08-25 14:17:52 +0200
committerMartin Möhrmann <martisch@uos.de>2016-08-29 18:25:33 +0000
commite6f9f39ce52e880b54e4cb08bf0cde73cf6c7dc2 (patch)
tree4b5c8de52c77c387944225e056c0890f3eaede52 /src/runtime/slice.go
parent595cebb055d327e52bd447985b53dcca869cea1d (diff)
downloadgo-e6f9f39ce52e880b54e4cb08bf0cde73cf6c7dc2.tar.gz
go-e6f9f39ce52e880b54e4cb08bf0cde73cf6c7dc2.zip
cmd/compile: generate makeslice calls with int arguments
Where possible generate calls to runtime makeslice with int arguments during compile time instead of makeslice with int64 arguments. This eliminates converting arguments for calls to makeslice with int64 arguments for platforms where int64 values do not fit into arguments of type int. godoc 386 binary shrinks by approximately 12 kilobyte. amd64: name old time/op new time/op delta MakeSlice-2 29.8ns ± 1% 29.8ns ± 1% ~ (p=1.000 n=24+24) 386: name old time/op new time/op delta MakeSlice-2 52.3ns ± 0% 45.9ns ± 0% -12.17% (p=0.000 n=25+22) Fixes #15357 Change-Id: Icb8701bb63c5a83877d26c8a4b78e782ba76de7c Reviewed-on: https://go-review.googlesource.com/27851 Run-TryBot: Martin Möhrmann <martisch@uos.de> 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.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index e15e6c4dc6..dd8dcb1873 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -36,21 +36,18 @@ func maxSliceCap(elemsize uintptr) uintptr {
return _MaxMem / elemsize
}
-// TODO: take uintptrs instead of int64s?
-func makeslice(et *_type, len64, cap64 int64) slice {
+func makeslice(et *_type, len, cap int) slice {
// NOTE: The len > maxElements check here is not strictly necessary,
// but it produces a 'len out of range' error instead of a 'cap out of range' error
// when someone does make([]T, bignumber). 'cap out of range' is true too,
// but since the cap is only being supplied implicitly, saying len is clearer.
// See issue 4085.
maxElements := maxSliceCap(et.size)
- len := int(len64)
- if len64 < 0 || int64(len) != len64 || uintptr(len) > maxElements {
+ if len < 0 || uintptr(len) > maxElements {
panic(errorString("makeslice: len out of range"))
}
- cap := int(cap64)
- if cap < len || int64(cap) != cap64 || uintptr(cap) > maxElements {
+ if cap < len || uintptr(cap) > maxElements {
panic(errorString("makeslice: cap out of range"))
}
@@ -58,6 +55,20 @@ func makeslice(et *_type, len64, cap64 int64) slice {
return slice{p, len, cap}
}
+func makeslice64(et *_type, len64, cap64 int64) slice {
+ len := int(len64)
+ if int64(len) != len64 {
+ panic(errorString("makeslice: len out of range"))
+ }
+
+ cap := int(cap64)
+ if int64(cap) != cap64 {
+ panic(errorString("makeslice: cap out of range"))
+ }
+
+ return makeslice(et, len, cap)
+}
+
// growslice handles slice growth during append.
// It is passed the slice element type, the old slice, and the desired new minimum capacity,
// and it returns a new slice with at least that capacity, with the old data