diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-03-26 17:28:46 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-03-26 17:28:46 +0800 |
commit | 1fae50a199903d28dac76e78ef065ba0ad96cf17 (patch) | |
tree | 06836e94cc3ef0153de197cfcbc6832c5f466628 /core/vm/intpool.go | |
parent | 933972d139b0fe291cb01c7ad2c0f9d3109a68dd (diff) | |
download | dexon-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar dexon-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.gz dexon-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.bz2 dexon-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.lz dexon-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.xz dexon-1fae50a199903d28dac76e78ef065ba0ad96cf17.tar.zst dexon-1fae50a199903d28dac76e78ef065ba0ad96cf17.zip |
core: minor evm polishes and optimizations
Diffstat (limited to 'core/vm/intpool.go')
-rw-r--r-- | core/vm/intpool.go | 16 |
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) } } |