From ff7d594bef6c25a7bcfb7084f9be6d956febec6c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 11 Aug 2021 13:25:58 +0300 Subject: [PATCH] vm: store refcounter directly in VM VM always has it, so allocating yet another object makes no sense. --- pkg/vm/slot.go | 2 +- pkg/vm/vm.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/vm/slot.go b/pkg/vm/slot.go index 22e4d8d5c..75601b309 100644 --- a/pkg/vm/slot.go +++ b/pkg/vm/slot.go @@ -26,7 +26,7 @@ func (s *Slot) init(n int) { } func (v *VM) newSlot(n int) *Slot { - s := newSlot(v.refs) + s := newSlot(&v.refs) s.init(n) return s } diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index be47455a7..9fe81d69d 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -73,7 +73,7 @@ type VM struct { uncaughtException stackitem.Item // exception being handled - refs *refCounter + refs refCounter gasConsumed int64 GasLimit int64 @@ -100,14 +100,14 @@ func NewWithTrigger(t trigger.Type) *VM { vm := &VM{ state: NoneState, istack: newStack("invocation", nil), - refs: newRefCounter(), trigger: t, SyscallHandler: defaultSyscallHandler, Invocations: make(map[util.Uint160]int), } - vm.estack = newStack("evaluation", vm.refs) + vm.refs.items = make(map[stackitem.Item]int) + vm.estack = newStack("evaluation", &vm.refs) return vm } @@ -281,11 +281,11 @@ func (v *VM) LoadScript(b []byte) { func (v *VM) LoadScriptWithFlags(b []byte, f callflag.CallFlag) { v.checkInvocationStackSize() ctx := NewContextWithParams(b, 0, -1, 0) - v.estack = newStack("evaluation", v.refs) + v.estack = newStack("evaluation", &v.refs) ctx.estack = v.estack ctx.tryStack = newStack("exception", nil) ctx.callFlag = f - ctx.static = newSlot(v.refs) + ctx.static = newSlot(&v.refs) ctx.callingScriptHash = v.GetCurrentScriptHash() v.istack.PushVal(ctx) }