vm: replace jumpIf with jump

`jumpIf` is used only once with non-constant condition.
This commit is contained in:
Evgenii Stratonikov 2020-07-20 14:51:15 +03:00
parent a45c160f10
commit aec9111961

View file

@ -1221,7 +1221,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
cond = getJumpCondition(op, a, b) cond = getJumpCondition(op, a, b)
} }
v.jumpIf(ctx, offset, cond) if cond {
v.jump(ctx, offset)
}
case opcode.CALL, opcode.CALLL: case opcode.CALL, opcode.CALLL:
v.checkInvocationStackSize() v.checkInvocationStackSize()
@ -1231,7 +1233,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
v.istack.PushVal(newCtx) v.istack.PushVal(newCtx)
offset := v.getJumpOffset(newCtx, parameter) offset := v.getJumpOffset(newCtx, parameter)
v.jumpIf(newCtx, offset, true) v.jump(newCtx, offset)
case opcode.CALLA: case opcode.CALLA:
ptr := v.estack.Pop().Item().(*stackitem.Pointer) ptr := v.estack.Pop().Item().(*stackitem.Pointer)
@ -1243,7 +1245,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
newCtx.local = nil newCtx.local = nil
newCtx.arguments = nil newCtx.arguments = nil
v.istack.PushVal(newCtx) v.istack.PushVal(newCtx)
v.jumpIf(newCtx, ptr.Position(), true) v.jump(newCtx, ptr.Position())
case opcode.SYSCALL: case opcode.SYSCALL:
interopID := GetInteropID(parameter) interopID := GetInteropID(parameter)
@ -1391,11 +1393,9 @@ func getJumpCondition(op opcode.Opcode, a, b *big.Int) bool {
} }
} }
// jumpIf performs jump to offset if cond is true. // jump performs jump to the offset.
func (v *VM) jumpIf(ctx *Context, offset int, cond bool) { func (v *VM) jump(ctx *Context, offset int) {
if cond { ctx.nextip = offset
ctx.nextip = offset
}
} }
// getJumpOffset returns instruction number in a current context // getJumpOffset returns instruction number in a current context