aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/intpool.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm/intpool.go')
-rw-r--r--core/vm/intpool.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/core/vm/intpool.go b/core/vm/intpool.go
index 384f5df59..5dbda18ee 100644
--- a/core/vm/intpool.go
+++ b/core/vm/intpool.go
@@ -32,24 +32,36 @@ func newIntPool() *intPool {
return &intPool{pool: newstack()}
}
+// get retrieves a big int from the pool, allocating one if the pool is empty.
+// Note, the returned int's value is arbitrary and will not be zeroed!
func (p *intPool) get() *big.Int {
if p.pool.len() > 0 {
return p.pool.pop()
}
return new(big.Int)
}
+
+// getZero retrieves a big int from the pool, setting it to zero or allocating
+// a new one if the pool is empty.
+func (p *intPool) getZero() *big.Int {
+ if p.pool.len() > 0 {
+ return p.pool.pop().SetUint64(0)
+ }
+ return new(big.Int)
+}
+
+// put returns an allocated big int to the pool to be later reused by get calls.
+// Note, the values as saved as is; neither put nor get zeroes the ints out!
func (p *intPool) put(is ...*big.Int) {
if len(p.pool.data) > poolLimit {
return
}
-
for _, i := range is {
// verifyPool is a build flag. Pool verification makes sure the integrity
// of the integer pool by comparing values to a default value.
if verifyPool {
i.Set(checkVal)
}
-
p.pool.push(i)
}
}