vm: store exception stack in the context

Avoid allocating it.
This commit is contained in:
Roman Khimov 2021-08-20 23:11:59 +03:00
parent d3198c3082
commit ed35cf8f12
3 changed files with 5 additions and 4 deletions

View file

@ -35,8 +35,8 @@ type Context struct {
local *Slot
arguments *Slot
// Exception context stack pointer.
tryStack *Stack
// Exception context stack.
tryStack Stack
// Script hash of the prog.
scriptHash util.Uint160

View file

@ -171,6 +171,7 @@ func initStack(s *Stack, n string, refc *refCounter) {
s.refs = refc
s.top.next = &s.top
s.top.prev = &s.top
s.len = 0
}
// Clear clears all elements on the stack and set its length to 0.

View file

@ -282,7 +282,7 @@ func (v *VM) LoadScriptWithFlags(b []byte, f callflag.CallFlag) {
ctx := NewContextWithParams(b, 0, -1, 0)
v.estack = newStack("evaluation", &v.refs)
ctx.estack = v.estack
ctx.tryStack = newStack("exception", nil)
initStack(&ctx.tryStack, "exception", nil)
ctx.callFlag = f
ctx.static = newSlot(&v.refs)
ctx.callingScriptHash = v.GetCurrentScriptHash()
@ -1519,7 +1519,7 @@ func (v *VM) call(ctx *Context, offset int) {
newCtx.RetCount = -1
newCtx.local = nil
newCtx.arguments = nil
newCtx.tryStack = newStack("exception", nil)
initStack(&newCtx.tryStack, "exception", nil)
newCtx.NEF = ctx.NEF
v.istack.PushVal(newCtx)
v.Jump(newCtx, offset)