mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Update list.go
This commit is contained in:
parent
51e875ee9d
commit
2fd4f2c7b7
1 changed files with 3 additions and 2 deletions
|
|
@ -160,13 +160,14 @@ func (m *sortedMap) Cap(threshold int) types.Transactions {
|
||||||
}
|
}
|
||||||
// Otherwise gather and drop the highest nonce'd transactions
|
// Otherwise gather and drop the highest nonce'd transactions
|
||||||
var drops types.Transactions
|
var drops types.Transactions
|
||||||
|
slices.Sort(*m.index)
|
||||||
slices.Sort(*m.index) // the sorted array is a heap, so no need to reheap after deleting tail items
|
|
||||||
for size := len(m.items); size > threshold; size-- {
|
for size := len(m.items); size > threshold; size-- {
|
||||||
drops = append(drops, m.items[(*m.index)[size-1]])
|
drops = append(drops, m.items[(*m.index)[size-1]])
|
||||||
delete(m.items, (*m.index)[size-1])
|
delete(m.items, (*m.index)[size-1])
|
||||||
}
|
}
|
||||||
*m.index = (*m.index)[:threshold]
|
*m.index = (*m.index)[:threshold]
|
||||||
|
// The sorted m.index slice is still a valid heap, so there is no need to
|
||||||
|
// reheap after deleting tail items.
|
||||||
|
|
||||||
// If we had a cache, shift the back
|
// If we had a cache, shift the back
|
||||||
m.cacheMu.Lock()
|
m.cacheMu.Lock()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue