mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
refactor Cap to use heap.Pop() instead of sorting the whole heap
This commit is contained in:
parent
d5ae16c486
commit
e8b23da4cd
1 changed files with 3 additions and 4 deletions
|
|
@ -160,12 +160,11 @@ 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
|
||||||
|
|
||||||
sort.Sort(*m.index)
|
|
||||||
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]])
|
dropIdx := m.index.Pop().(uint64)
|
||||||
delete(m.items, (*m.index)[size-1])
|
drops = append(drops, m.items[dropIdx])
|
||||||
|
delete(m.items, dropIdx)
|
||||||
}
|
}
|
||||||
*m.index = (*m.index)[:threshold]
|
|
||||||
|
|
||||||
// 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