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:
parent
ff7d594bef
commit
bdb2d24a5a
2 changed files with 12 additions and 10 deletions
|
@ -162,13 +162,15 @@ func NewStack(n string) *Stack {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStack(n string, refc *refCounter) *Stack {
|
func newStack(n string, refc *refCounter) *Stack {
|
||||||
s := &Stack{
|
s := new(Stack)
|
||||||
name: n,
|
initStack(s, n, refc)
|
||||||
refs: refc,
|
return s
|
||||||
}
|
}
|
||||||
|
func initStack(s *Stack, n string, refc *refCounter) {
|
||||||
|
s.name = n
|
||||||
|
s.refs = refc
|
||||||
s.top.next = &s.top
|
s.top.next = &s.top
|
||||||
s.top.prev = &s.top
|
s.top.prev = &s.top
|
||||||
return s
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear clears all elements on the stack and set its length to 0.
|
// Clear clears all elements on the stack and set its length to 0.
|
||||||
|
|
10
pkg/vm/vm.go
10
pkg/vm/vm.go
|
@ -68,7 +68,7 @@ type VM struct {
|
||||||
// callback to get interop price
|
// callback to get interop price
|
||||||
getPrice func(opcode.Opcode, []byte) int64
|
getPrice func(opcode.Opcode, []byte) int64
|
||||||
|
|
||||||
istack *Stack // invocation stack.
|
istack Stack // invocation stack.
|
||||||
estack *Stack // execution stack.
|
estack *Stack // execution stack.
|
||||||
|
|
||||||
uncaughtException stackitem.Item // exception being handled
|
uncaughtException stackitem.Item // exception being handled
|
||||||
|
@ -99,7 +99,6 @@ func New() *VM {
|
||||||
func NewWithTrigger(t trigger.Type) *VM {
|
func NewWithTrigger(t trigger.Type) *VM {
|
||||||
vm := &VM{
|
vm := &VM{
|
||||||
state: NoneState,
|
state: NoneState,
|
||||||
istack: newStack("invocation", nil),
|
|
||||||
trigger: t,
|
trigger: t,
|
||||||
|
|
||||||
SyscallHandler: defaultSyscallHandler,
|
SyscallHandler: defaultSyscallHandler,
|
||||||
|
@ -107,6 +106,7 @@ func NewWithTrigger(t trigger.Type) *VM {
|
||||||
}
|
}
|
||||||
|
|
||||||
vm.refs.items = make(map[stackitem.Item]int)
|
vm.refs.items = make(map[stackitem.Item]int)
|
||||||
|
initStack(&vm.istack, "invocation", nil)
|
||||||
vm.estack = newStack("evaluation", &vm.refs)
|
vm.estack = newStack("evaluation", &vm.refs)
|
||||||
return vm
|
return vm
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ func (v *VM) Estack() *Stack {
|
||||||
|
|
||||||
// Istack returns the invocation stack so interop hooks can utilize this.
|
// Istack returns the invocation stack so interop hooks can utilize this.
|
||||||
func (v *VM) Istack() *Stack {
|
func (v *VM) Istack() *Stack {
|
||||||
return v.istack
|
return &v.istack
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadArgs loads in the arguments used in the Mian entry point.
|
// 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 {
|
func (v *VM) Stack(n string) string {
|
||||||
var s *Stack
|
var s *Stack
|
||||||
if n == "istack" {
|
if n == "istack" {
|
||||||
s = v.istack
|
s = &v.istack
|
||||||
}
|
}
|
||||||
if n == "estack" {
|
if n == "estack" {
|
||||||
s = v.estack
|
s = v.estack
|
||||||
|
@ -1786,7 +1786,7 @@ func (v *VM) GetCallingScriptHash() util.Uint160 {
|
||||||
|
|
||||||
// GetEntryScriptHash implements ScriptHashGetter interface.
|
// GetEntryScriptHash implements ScriptHashGetter interface.
|
||||||
func (v *VM) GetEntryScriptHash() util.Uint160 {
|
func (v *VM) GetEntryScriptHash() util.Uint160 {
|
||||||
return v.getContextScriptHash(v.Istack().Len() - 1)
|
return v.getContextScriptHash(v.istack.len - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentScriptHash implements ScriptHashGetter interface.
|
// GetCurrentScriptHash implements ScriptHashGetter interface.
|
||||||
|
|
Loading…
Reference in a new issue