compiler: do not store constants as variables

Because the constants are loaded directly via `emitLoadConst`, there is no need to store
them in an array of locals. It can have a big overhead, because it
is done at the beginning of every function.
This commit is contained in:
Evgenii Stratonikov 2020-02-03 13:29:23 +03:00
parent 48ca0e1126
commit c3094123a1

View file

@ -138,7 +138,11 @@ func (c *codegen) convertGlobals(f ast.Node) {
case *ast.FuncDecl: case *ast.FuncDecl:
return false return false
case *ast.GenDecl: case *ast.GenDecl:
ast.Walk(c, n) // constants are loaded directly so there is no need
// to store them as a local variables
if n.Tok != token.CONST {
ast.Walk(c, n)
}
} }
return true return true
}) })