mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
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:
parent
10110d4e70
commit
3d4076ca36
2 changed files with 9 additions and 1 deletions
|
@ -132,6 +132,14 @@ func newStack(n string, refc *refCounter) *Stack {
|
||||||
initStack(s, n, refc)
|
initStack(s, n, refc)
|
||||||
return s
|
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) {
|
func initStack(s *Stack, n string, refc *refCounter) {
|
||||||
s.name = n
|
s.name = n
|
||||||
s.refs = refc
|
s.refs = refc
|
||||||
|
|
|
@ -322,7 +322,7 @@ func (v *VM) loadScriptWithCallingHash(b []byte, exe *nef.File, caller util.Uint
|
||||||
v.checkInvocationStackSize()
|
v.checkInvocationStackSize()
|
||||||
ctx := NewContextWithParams(b, rvcount, offset)
|
ctx := NewContextWithParams(b, rvcount, offset)
|
||||||
if rvcount != -1 || v.estack.Len() != 0 {
|
if rvcount != -1 || v.estack.Len() != 0 {
|
||||||
v.estack = newStack("evaluation", &v.refs)
|
v.estack = subStack(v.estack)
|
||||||
}
|
}
|
||||||
ctx.estack = v.estack
|
ctx.estack = v.estack
|
||||||
initStack(&ctx.tryStack, "exception", nil)
|
initStack(&ctx.tryStack, "exception", nil)
|
||||||
|
|
Loading…
Reference in a new issue