]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: avoid allocation in Nodes.Set in common case
authorRobert Griesemer <gri@golang.org>
Mon, 28 Mar 2016 21:12:10 +0000 (14:12 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 28 Mar 2016 21:41:11 +0000 (21:41 +0000)
commit621aa713d46c3eebbc03e352436d109f28779e47
treeecc103049b544a37adf149d92b997aa8bfbfa77a
parent390d1ce686729dea40cee796ce391f9fd8466942
cmd/compile: avoid allocation in Nodes.Set in common case

When building make.bash, calling Nodes.Set(s) where len(s) == 0 occurs
4738678 times vs 1465415 calls where len(s) > 0; i.e., it is over 3x
more common to set Nodes.slice to nil rather than to s.

Make a copy of slice (header) and take address of that copy instead
to avoid allocating the argument slice on the heap always even when
not needed.

Saves 4738678 slice header allocations and slice header value copies.

Change-Id: I88e8e919ea9868ceb2df46173d187af4109bd947
Reviewed-on: https://go-review.googlesource.com/21241
Reviewed-by: Alan Donovan <adonovan@google.com>
src/cmd/compile/internal/gc/syntax.go