diff options
author | Robert Griesemer <gri@golang.org> | 2017-03-21 22:23:15 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2017-03-22 22:37:08 +0000 |
commit | b5f81eae17b68c9a34d23dcf4669e3d879781b35 (patch) | |
tree | 3a8827c045d3d219bfd306318429d834ca575887 /src/cmd/compile/internal/syntax/printer.go | |
parent | e0329248d5cda9a6a6c1492a2fdeeacd982afc9c (diff) | |
download | go-b5f81eae17b68c9a34d23dcf4669e3d879781b35.tar.gz go-b5f81eae17b68c9a34d23dcf4669e3d879781b35.zip |
cmd/compile/internal/syntax: replace inlined statement lists with syntax.BlockStmt
This simplifies the code and removes a premature optimization.
It increases the amount of allocated syntax.Node space by ~0.4%
for parsing all of std lib, which is negligible.
Before the change (best of 5 runs):
$ go test -run StdLib -fast
parsed 1517022 lines (3394 files) in 793.487886ms (1911840 lines/s)
allocated 387.086Mb (267B/line, 487.828Mb/s)
After the change (best of 5 runs):
$ go test -run StdLib -fast
parsed 1516911 lines (3392 files) in 805.028655ms (1884294 lines/s)
allocated 388.466Mb (268B/line, 482.549Mb/s)
Change-Id: Id19d6210fdc62393862ba3b04913352d95c599be
Reviewed-on: https://go-review.googlesource.com/38439
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/printer.go')
-rw-r--r-- | src/cmd/compile/internal/syntax/printer.go | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/src/cmd/compile/internal/syntax/printer.go b/src/cmd/compile/internal/syntax/printer.go index 43876a25c2..426921199e 100644 --- a/src/cmd/compile/internal/syntax/printer.go +++ b/src/cmd/compile/internal/syntax/printer.go @@ -349,8 +349,7 @@ func (p *printer) printRawNode(n Node) { p.print(_Name, n.Value) // _Name requires actual value following immediately case *FuncLit: - p.print(n.Type, blank) - p.printBody(n.Body) + p.print(n.Type, blank, n.Body) case *CompositeLit: if n.Type != nil { @@ -524,15 +523,20 @@ func (p *printer) printRawNode(n Node) { } case *BlockStmt: - p.printBody(n.Body) + p.print(_Lbrace) + if len(n.List) > 0 { + p.print(newline, indent) + p.printStmtList(n.List, true) + p.print(outdent, newline) + } + p.print(_Rbrace) case *IfStmt: p.print(_If, blank) if n.Init != nil { p.print(n.Init, _Semi, blank) } - p.print(n.Cond, blank) - p.printBody(n.Then) + p.print(n.Cond, blank, n.Then) if n.Else != nil { p.print(blank, _Else, blank, n.Else) } @@ -578,8 +582,7 @@ func (p *printer) printRawNode(n Node) { p.print(n.Init) // TODO(gri) clean this up if _, ok := n.Init.(*RangeClause); ok { - p.print(blank) - p.printBody(n.Body) + p.print(blank, n.Body) break } } @@ -592,7 +595,7 @@ func (p *printer) printRawNode(n Node) { p.print(n.Post, blank) } } - p.printBody(n.Body) + p.print(n.Body) case *ImportDecl: if n.Group == nil { @@ -650,8 +653,7 @@ func (p *printer) printRawNode(n Node) { p.print(n.Name) p.printSignature(n.Type) if n.Body != nil { - p.print(blank) - p.printBody(n.Body) + p.print(blank, n.Body) } case *printGroup: @@ -882,16 +884,6 @@ func (p *printer) printStmtList(list []Stmt, braces bool) { } } -func (p *printer) printBody(list []Stmt) { - p.print(_Lbrace) - if len(list) > 0 { - p.print(newline, indent) - p.printStmtList(list, true) - p.print(outdent, newline) - } - p.print(_Rbrace) -} - func (p *printer) printSwitchBody(list []*CaseClause) { p.print(_Lbrace) if len(list) > 0 { |