aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/stack.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm/stack.go')
-rw-r--r--core/vm/stack.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/core/vm/stack.go b/core/vm/stack.go
index 4c1b9e803..14b1c289b 100644
--- a/core/vm/stack.go
+++ b/core/vm/stack.go
@@ -19,8 +19,15 @@ package vm
import (
"fmt"
"math/big"
+ "sync"
)
+var stackPool = sync.Pool{
+ New: func() interface{} {
+ return &Stack{data: make([]*big.Int, 0, 1024)}
+ },
+}
+
// Stack is an object for basic stack operations. Items popped to the stack are
// expected to be changed and modified. stack does not take care of adding newly
// initialised objects.
@@ -29,7 +36,13 @@ type Stack struct {
}
func newstack() *Stack {
- return &Stack{data: make([]*big.Int, 0, 1024)}
+ stack := stackPool.Get().(*Stack)
+ stack.data = stack.data[:0]
+ return stack
+}
+
+func recyclestack(stack *Stack) {
+ stackPool.Put(stack)
}
// Data returns the underlying big.Int array.