diff options
| author | Josh Bleecher Snyder <josharian@gmail.com> | 2016-04-19 09:18:59 -0700 |
|---|---|---|
| committer | Josh Bleecher Snyder <josharian@gmail.com> | 2016-04-19 21:38:52 +0000 |
| commit | a4dd6ea1524901fab5deac60772345babd058ae7 (patch) | |
| tree | 413af3884aff44e753fe46c98cb4f66f95763a7c /src/runtime/malloc.go | |
| parent | 55ab07c224a358cabe795fb1e52a627194d7daee (diff) | |
| download | go-a4dd6ea1524901fab5deac60772345babd058ae7.tar.xz | |
runtime: add maxSliceCap
This avoids expensive division calculations
for many common slice element sizes.
name old time/op new time/op delta
MakeSlice-8 51.9ns ± 3% 35.1ns ± 2% -32.41% (p=0.000 n=10+10)
GrowSliceBytes-8 44.1ns ± 2% 44.1ns ± 1% ~ (p=0.984 n=10+10)
GrowSliceInts-8 60.9ns ± 3% 60.9ns ± 3% ~ (p=0.698 n=10+10)
GrowSlicePtr-8 131ns ± 1% 120ns ± 2% -8.41% (p=0.000 n=8+10)
GrowSliceStruct24Bytes-8 111ns ± 2% 103ns ± 3% -7.23% (p=0.000 n=8+8)
Change-Id: I2630eb3d73c814db030cad16e620ea7fecbbd312
Reviewed-on: https://go-review.googlesource.com/22223
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/malloc.go')
| -rw-r--r-- | src/runtime/malloc.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index ee4728c9a5..a3e55ec2fb 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -792,7 +792,7 @@ func newarray(typ *_type, n uintptr) unsafe.Pointer { if typ.kind&kindNoPointers != 0 { flags |= flagNoScan } - if int(n) < 0 || (typ.size > 0 && n > _MaxMem/typ.size) { + if int(n) < 0 || n > maxSliceCap(typ.size) { panic(plainError("runtime: allocation size out of range")) } return mallocgc(typ.size*n, typ, flags) |
