aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2017-07-16 17:46:52 -1000
committerJosh Bleecher Snyder <josharian@gmail.com>2017-08-14 23:32:03 +0000
commit29e9b89b9ada73fa7775b351c100709c330c0a46 (patch)
treee5ba3ae68b465dcca720be7bec91410ddf059d16 /src
parent733567a1860956e87daa1a2fa46d58fc44b896cc (diff)
downloadgo-29e9b89b9ada73fa7775b351c100709c330c0a46.tar.xz
runtime: special case allocation of arrays of size 1
This avoids division and multiplication. Instrumentation suggests that this is a very common case. Change-Id: I2d5d5012d4f4df4c4af1f9f85ca9c323c9889c0e Reviewed-on: https://go-review.googlesource.com/54657 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')
-rw-r--r--src/runtime/malloc.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 0ebd2c0ab2..274ab537fc 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -847,6 +847,9 @@ func reflect_unsafe_New(typ *_type) unsafe.Pointer {
// newarray allocates an array of n elements of type typ.
func newarray(typ *_type, n int) unsafe.Pointer {
+ if n == 1 {
+ return mallocgc(typ.size, typ, true)
+ }
if n < 0 || uintptr(n) > maxSliceCap(typ.size) {
panic(plainError("runtime: allocation size out of range"))
}