forked from TrueCloudLab/neoneo-go
mempool: do not allocate new slice for verified transactions
Because transactions a iterated in an increasing order, we can filter slice in-place.
This commit is contained in:
parent
0ef7a76e84
commit
cbf26bac83
1 changed files with 3 additions and 3 deletions
|
@ -260,9 +260,9 @@ func (mp *Pool) Remove(hash util.Uint256) {
|
||||||
// drop part of the mempool that is now invalid after the block acceptance.
|
// drop part of the mempool that is now invalid after the block acceptance.
|
||||||
func (mp *Pool) RemoveStale(isOK func(*transaction.Transaction) bool) {
|
func (mp *Pool) RemoveStale(isOK func(*transaction.Transaction) bool) {
|
||||||
mp.lock.Lock()
|
mp.lock.Lock()
|
||||||
// We expect a lot of changes, so it's easier to allocate a new slice
|
// We can reuse already allocated slice
|
||||||
// rather than move things in an old one.
|
// because items are iterated one-by-one in increasing order.
|
||||||
newVerifiedTxes := make([]*item, 0, mp.capacity)
|
newVerifiedTxes := mp.verifiedTxes[:0]
|
||||||
newInputs := mp.inputs[:0]
|
newInputs := mp.inputs[:0]
|
||||||
newClaims := mp.claims[:0]
|
newClaims := mp.claims[:0]
|
||||||
for _, itm := range mp.verifiedTxes {
|
for _, itm := range mp.verifiedTxes {
|
||||||
|
|
Loading…
Reference in a new issue