go/types: less closure creations in gcimporter.

Closures are incredibly expensive on linux/arm due to
repetitive flush of instruction cache.

go test -short on ODROID-X:

Before:
ok      exp/gotype      17.091s
ok      go/types        2.225s

After:
ok      exp/gotype      7.193s
ok      go/types        1.143s

R=dave, minux.ma, rsc
CC=golang-dev, remy
https://golang.org/cl/7062045
This commit is contained in:
Rémy Oudompheng 2013-01-06 23:38:38 +01:00
parent 1e1aea6821
commit 0f545d9ab2
1 changed files with 15 additions and 30 deletions

View File

@ -408,18 +408,13 @@ func (p *gcParser) parseField() *Field {
func (p *gcParser) parseStructType() Type { func (p *gcParser) parseStructType() Type {
var fields []*Field var fields []*Field
parseField := func() {
fields = append(fields, p.parseField())
}
p.expectKeyword("struct") p.expectKeyword("struct")
p.expect('{') p.expect('{')
if p.tok != '}' { for p.tok != '}' {
parseField() if len(fields) > 0 {
for p.tok == ';' { p.expect(';')
p.next()
parseField()
} }
fields = append(fields, p.parseField())
} }
p.expect('}') p.expect('}')
@ -450,7 +445,11 @@ func (p *gcParser) parseParameter() (par *Var, isVariadic bool) {
// ParameterList = { Parameter "," } Parameter . // ParameterList = { Parameter "," } Parameter .
// //
func (p *gcParser) parseParameters() (list []*Var, isVariadic bool) { func (p *gcParser) parseParameters() (list []*Var, isVariadic bool) {
parseParameter := func() { p.expect('(')
for p.tok != ')' {
if len(list) > 0 {
p.expect(',')
}
par, variadic := p.parseParameter() par, variadic := p.parseParameter()
list = append(list, par) list = append(list, par)
if variadic { if variadic {
@ -460,15 +459,6 @@ func (p *gcParser) parseParameters() (list []*Var, isVariadic bool) {
isVariadic = true isVariadic = true
} }
} }
p.expect('(')
if p.tok != ')' {
parseParameter()
for p.tok == ',' {
p.next()
parseParameter()
}
}
p.expect(')') p.expect(')')
return return
@ -509,21 +499,16 @@ func (p *gcParser) parseSignature() *Signature {
func (p *gcParser) parseInterfaceType() Type { func (p *gcParser) parseInterfaceType() Type {
var methods []*Method var methods []*Method
parseMethod := func() { p.expectKeyword("interface")
p.expect('{')
for p.tok != '}' {
if len(methods) > 0 {
p.expect(';')
}
name := p.parseName() name := p.parseName()
typ := p.parseSignature() typ := p.parseSignature()
methods = append(methods, &Method{name, typ}) methods = append(methods, &Method{name, typ})
} }
p.expectKeyword("interface")
p.expect('{')
if p.tok != '}' {
parseMethod()
for p.tok == ';' {
p.next()
parseMethod()
}
}
p.expect('}') p.expect('}')
return &Interface{Methods: methods} return &Interface{Methods: methods}