mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-19 13:26:47 +00:00

* [NOD-1006] Make CompactToBig take an out param so that we can reuse the same big.Int in averageTarget. * [NOD-1006] Fix merge errors. * [NOD-1006] Use CompactToBigWithDestination only in averageTarget. * [NOD-1006] Fix refactor errors. * [NOD-1006] Fix refactor errors. * [NOD-1006] Optimize averageTarget with a big.Int pool. * [NOD-1006] Defer releasing bigInts. * [NOD-1006] Use a pool for requiredDifficulty as well. * [NOD-1006] Move the big int pool to utils. * [NOD-1006] Remove unnecessary line.
26 lines
433 B
Go
26 lines
433 B
Go
package bigintpool
|
|
|
|
import (
|
|
"math/big"
|
|
"sync"
|
|
)
|
|
|
|
var bigIntPool = sync.Pool{
|
|
New: func() interface{} {
|
|
return big.NewInt(0)
|
|
},
|
|
}
|
|
|
|
// Acquire acquires a big.Int from the pool and
|
|
// initializes it to x.
|
|
func Acquire(x int64) *big.Int {
|
|
bigInt := bigIntPool.Get().(*big.Int)
|
|
bigInt.SetInt64(x)
|
|
return bigInt
|
|
}
|
|
|
|
// Release returns the given big.Int to the pool.
|
|
func Release(toRelease *big.Int) {
|
|
bigIntPool.Put(toRelease)
|
|
}
|