vm: microoptimize new estack creation

Subslice won't reach element -1, but it can reuse the same buffer space more
effectively.
This commit is contained in:
Roman Khimov 2022-05-31 18:53:05 +03:00
parent 10110d4e70
commit 3d4076ca36
2 changed files with 9 additions and 1 deletions

View file

@ -132,6 +132,14 @@ func newStack(n string, refc *refCounter) *Stack {
initStack(s, n, refc)
return s
}
func subStack(old *Stack) *Stack {
s := new(Stack)
*s = *old
s.elems = s.elems[len(s.elems):]
return s
}
func initStack(s *Stack, n string, refc *refCounter) {
s.name = n
s.refs = refc

View file

@ -322,7 +322,7 @@ func (v *VM) loadScriptWithCallingHash(b []byte, exe *nef.File, caller util.Uint
v.checkInvocationStackSize()
ctx := NewContextWithParams(b, rvcount, offset)
if rvcount != -1 || v.estack.Len() != 0 {
v.estack = newStack("evaluation", &v.refs)
v.estack = subStack(v.estack)
}
ctx.estack = v.estack
initStack(&ctx.tryStack, "exception", nil)