compiler: do not load values which will be dropped

This commit is contained in:
Evgenii Stratonikov 2020-06-19 17:37:07 +03:00
parent 72be5412f4
commit 1847c28b42

View file

@ -924,7 +924,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
emit.Opcode(c.prog.BinWriter, opcode.OVER) emit.Opcode(c.prog.BinWriter, opcode.OVER)
emit.Jmp(c.prog.BinWriter, opcode.JMPLEL, end) emit.Jmp(c.prog.BinWriter, opcode.JMPLEL, end)
if n.Key != nil { if n.Key != nil && n.Key.(*ast.Ident).Name != "_" {
if isMap { if isMap {
c.rangeLoadKey() c.rangeLoadKey()
} else { } else {
@ -932,7 +932,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
} }
c.emitStoreVar(n.Key.(*ast.Ident).Name) c.emitStoreVar(n.Key.(*ast.Ident).Name)
} }
if n.Value != nil { if n.Value != nil && n.Value.(*ast.Ident).Name != "_" {
c.rangeLoadKey() c.rangeLoadKey()
if isMap { if isMap {
// we have loaded only key from key array, now load value // we have loaded only key from key array, now load value