vm: remove istack redirection in VM

VM always has istack and it doesn't even change, so doing this microallocation
makes no sense. Notice that estack is a bit harder to change we do replace it
in some cases and we compare pointers to it as well.
This commit is contained in:
Roman Khimov 2021-08-11 14:40:41 +03:00
parent ff7d594bef
commit bdb2d24a5a
2 changed files with 12 additions and 10 deletions

View file

@ -162,13 +162,15 @@ func NewStack(n string) *Stack {
}
func newStack(n string, refc *refCounter) *Stack {
s := &Stack{
name: n,
refs: refc,
}
s := new(Stack)
initStack(s, n, refc)
return s
}
func initStack(s *Stack, n string, refc *refCounter) {
s.name = n
s.refs = refc
s.top.next = &s.top
s.top.prev = &s.top
return s
}
// Clear clears all elements on the stack and set its length to 0.

View file

@ -68,7 +68,7 @@ type VM struct {
// callback to get interop price
getPrice func(opcode.Opcode, []byte) int64
istack *Stack // invocation stack.
istack Stack // invocation stack.
estack *Stack // execution stack.
uncaughtException stackitem.Item // exception being handled
@ -99,7 +99,6 @@ func New() *VM {
func NewWithTrigger(t trigger.Type) *VM {
vm := &VM{
state: NoneState,
istack: newStack("invocation", nil),
trigger: t,
SyscallHandler: defaultSyscallHandler,
@ -107,6 +106,7 @@ func NewWithTrigger(t trigger.Type) *VM {
}
vm.refs.items = make(map[stackitem.Item]int)
initStack(&vm.istack, "invocation", nil)
vm.estack = newStack("evaluation", &vm.refs)
return vm
}
@ -135,7 +135,7 @@ func (v *VM) Estack() *Stack {
// Istack returns the invocation stack so interop hooks can utilize this.
func (v *VM) Istack() *Stack {
return v.istack
return &v.istack
}
// LoadArgs loads in the arguments used in the Mian entry point.
@ -340,7 +340,7 @@ func (v *VM) PopResult() interface{} {
func (v *VM) Stack(n string) string {
var s *Stack
if n == "istack" {
s = v.istack
s = &v.istack
}
if n == "estack" {
s = v.estack
@ -1786,7 +1786,7 @@ func (v *VM) GetCallingScriptHash() util.Uint160 {
// GetEntryScriptHash implements ScriptHashGetter interface.
func (v *VM) GetEntryScriptHash() util.Uint160 {
return v.getContextScriptHash(v.Istack().Len() - 1)
return v.getContextScriptHash(v.istack.len - 1)
}
// GetCurrentScriptHash implements ScriptHashGetter interface.