package internal

import "math/big"

const maxPoolCount = 1024

// bnPool implements a tiny cache of *big.Int objects that's used to reduce the
// number of allocations made during processing.

// TODO bnPool 必须在每个线程中一个。只有将SM2的操作定义为sm2对象的方法，在初始化对象的时候定义一个.
// 并且，该对象不能被多线程共享。

type bnPool struct {
	bns []*big.Int
}

func (pool *bnPool) Get() *big.Int {
	l := len(pool.bns)
	if l > 0 {
		bn := pool.bns[l-1]
		pool.bns = pool.bns[:l-1]
		return bn
	}
	return new(big.Int)
}

func (pool *bnPool) Put(bn *big.Int) {
	pool.bns = append(pool.bns, bn)

}

func (pool *bnPool) Count() int {
	return len(pool.bns)
}
