cmd/compile: reduce slice header allocation when parsing := assignments

The colas function allocates 2 slice headers in each call (via Nodes.Set)
only to throw away those slice headers in the common case where both the
lhs and rhs in "lhs := rhs" have length 1.

Avoid the Nodes.Set calls in those cases. For make.bash, this eliminates
~63,000 slice header allocations.

Also: Minor cleanups in colasdefn.

Change-Id: Ib114a67c3adeb8821868bd71a5e0f5e2e19fcd4f
Reviewed-on: https://go-review.googlesource.com/21170
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Robert Griesemer 2016-03-25 15:34:55 -07:00
parent a7f7a9cca7
commit 135109d241
3 changed files with 24 additions and 30 deletions

View file

@ -636,7 +636,7 @@ func (p *parser) simple_stmt(labelOk, rangeOk bool) *Node {
r := Nod(ORANGE, nil, p.expr())
r.List.Set(lhs)
r.Colas = true
colasdefn(r.List, r)
colasdefn(lhs, r)
return r
}