]> Cypherpunks repositories - gostls13.git/commit
runtime: reduce slice growth during append to 2x
authorRuss Cox <rsc@golang.org>
Thu, 25 Jun 2015 23:27:20 +0000 (19:27 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 26 Jun 2015 17:49:33 +0000 (17:49 +0000)
commit32fddadd98f938018485fba6253d30273db4e5e9
treed00bea248ea247fd5133c3502225ea0c60e77f50
parent1284d7d403875d11cff97dfb7c946a7ee11e1569
runtime: reduce slice growth during append to 2x

The new inlined code for append assumed that it could pass the
desired new cap to growslice, not the number of new elements.
But growslice still interpreted the argument as the number of new elements,
making it always grow by >2x (more precisely, 2x+1 rounded up
to the next malloc block size). At the time, I had intended to change
the other callers to use the new cap as well, but it's too late for that.
Instead, introduce growslice_n for the old callers and keep growslice
for the inlined (common case) caller.

Fixes #11403.

Filed #11419 to merge them.

Change-Id: I1338b1e5b352f3be4e43641f44b652ef7195251b
Reviewed-on: https://go-review.googlesource.com/11541
Reviewed-by: Austin Clements <austin@google.com>
src/cmd/compile/internal/gc/builtin.go
src/cmd/compile/internal/gc/builtin/runtime.go
src/cmd/compile/internal/gc/walk.go
src/runtime/runtime_test.go
src/runtime/slice.go