Commit 79d2115e authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: eliminate more allocs in newblock

name       old allocs/op    new allocs/op    delta
Template         389k ± 0%        386k ± 0%  -0.84%        (p=0.000 n=10+10)
Unicode          323k ± 0%        323k ± 0%  -0.25%        (p=0.000 n=10+10)
GoTypes         1.17M ± 0%       1.16M ± 0%  -0.93%        (p=0.000 n=10+10)
Compiler        4.13M ± 0%       4.09M ± 0%  -1.05%        (p=0.000 n=10+10)

Change-Id: I6c00850d07511c2e65761c7373fc3df738499105
Reviewed-on: https://go-review.googlesource.com/32235
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 23d762c1
......@@ -109,16 +109,22 @@ func newblock(prog *obj.Prog) *BasicBlock {
if prog == nil {
Fatalf("newblock: prog cannot be nil")
}
result := new(BasicBlock)
// type block allows us to allocate a BasicBlock
// and its pred/succ slice together.
type block struct {
result BasicBlock
pred [2]*BasicBlock
succ [2]*BasicBlock
}
b := new(block)
result := &b.result
result.rpo = -1
result.mark = UNVISITED
result.first = prog
result.last = prog
// We want two 0-len slices with capacity 2.
// Carve them out of a single allocation.
blocks := make([]*BasicBlock, 4)
result.pred = blocks[0:][:0:2]
result.succ = blocks[2:][:0:2]
result.pred = b.pred[:0]
result.succ = b.succ[:0]
return result
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment