]> Cypherpunks repositories - gostls13.git/commit
runtime: speed up growslice by avoiding divisions
authorMartin Möhrmann <martisch@uos.de>
Sun, 13 Mar 2016 17:58:17 +0000 (18:58 +0100)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 14 Mar 2016 00:45:57 +0000 (00:45 +0000)
commit43ed65f869828f8dfc2f860b8ca1f7648e6bb93d
tree7ae05791a1110a4e7b9bfeffe1a47971b8db5bba
parentb55a5dbb8acacf99007d3505c5a763d48c684bb4
runtime: speed up growslice by avoiding divisions

Only compute the number of maximum allowed elements per slice once.
Special case newcap computation for slices with byte sized elements.

name              old time/op  new time/op  delta
GrowSliceBytes-2  61.1ns ± 1%  43.4ns ± 1%  -29.00%  (p=0.000 n=20+20)
GrowSliceInts-2   85.9ns ± 1%  75.7ns ± 1%  -11.80%  (p=0.000 n=20+20)

Change-Id: I5d9c0d5987cdd108ac29dc32e31912dcefa2324d
Reviewed-on: https://go-review.googlesource.com/20653
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/runtime/append_test.go
src/runtime/slice.go