diff options
author | Martin Möhrmann <moehrmann@google.com> | 2018-04-26 18:30:11 +0200 |
---|---|---|
committer | Martin Möhrmann <moehrmann@google.com> | 2018-05-06 04:28:23 +0000 |
commit | a8a60ac2a7bec701de6b502889e1dc740761e183 (patch) | |
tree | c53e32a00f0fc81f45099b0eadca4cfd6846ee24 /test/append1.go | |
parent | 87412a143051d63f4ce68900f4668b2a3fb5c4f2 (diff) | |
download | go-a8a60ac2a7bec701de6b502889e1dc740761e183.tar.gz go-a8a60ac2a7bec701de6b502889e1dc740761e183.zip |
cmd/compile: optimize append(x, make([]T, y)...) slice extension
Changes the compiler to recognize the slice extension pattern
append(x, make([]T, y)...)
and replace it with growslice and an optional memclr to avoid an allocation for make([]T, y).
Memclr is not called in case growslice already allocated a new cleared backing array
when T contains pointers.
amd64:
name old time/op new time/op delta
ExtendSlice/IntSlice 103ns ± 4% 57ns ± 4% -44.55% (p=0.000 n=18+18)
ExtendSlice/PointerSlice 155ns ± 3% 77ns ± 3% -49.93% (p=0.000 n=20+20)
ExtendSlice/NoGrow 50.2ns ± 3% 5.2ns ± 2% -89.67% (p=0.000 n=18+18)
name old alloc/op new alloc/op delta
ExtendSlice/IntSlice 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.000 n=20+20)
ExtendSlice/PointerSlice 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.000 n=20+20)
ExtendSlice/NoGrow 32.0B ± 0% 0.0B -100.00% (p=0.000 n=20+20)
name old allocs/op new allocs/op delta
ExtendSlice/IntSlice 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=20+20)
ExtendSlice/PointerSlice 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=20+20)
ExtendSlice/NoGrow 1.00 ± 0% 0.00 -100.00% (p=0.000 n=20+20)
Fixes #21266
Change-Id: Idc3077665f63cbe89762b590c5967a864fd1c07f
Reviewed-on: https://go-review.googlesource.com/109517
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 'test/append1.go')
-rw-r--r-- | test/append1.go | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/test/append1.go b/test/append1.go index 6d42368e42..0fe24c0956 100644 --- a/test/append1.go +++ b/test/append1.go @@ -17,4 +17,6 @@ func main() { _ = append(s...) // ERROR "cannot use ... on first argument" _ = append(s, 2, s...) // ERROR "too many arguments to append" + _ = append(s, make([]int, 0)) // ERROR "cannot use make.* as type int in append" + _ = append(s, make([]int, -1)...) // ERROR "negative len argument in make" } |