compiler: optimize append argument processing

Append should leave it's result on top of the stack.
Thus we need to transform top of the stack:
(top) a . b --> (top) a . b . b
It can be done with just OVER + SWAP.
This commit is contained in:
Evgenii Stratonikov 2020-01-29 10:24:35 +03:00
parent b6629fb6bd
commit 7053b3b2c0

View file

@ -744,10 +744,8 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
if isByteArrayType(typ) {
emitOpcode(c.prog.BinWriter, opcode.CAT)
} else {
emitOpcode(c.prog.BinWriter, opcode.OVER)
emitOpcode(c.prog.BinWriter, opcode.SWAP)
emitOpcode(c.prog.BinWriter, opcode.DUP)
emitOpcode(c.prog.BinWriter, opcode.PUSH2)
emitOpcode(c.prog.BinWriter, opcode.XSWAP)
emitOpcode(c.prog.BinWriter, opcode.APPEND)
}
case "panic":