Skip to content

Commit e8b23da

Browse files
author
colinlyguo
committed
refactor Cap to use heap.Pop() instead of sorting the whole heap
1 parent d5ae16c commit e8b23da

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

core/txpool/legacypool/list.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,11 @@ func (m *sortedMap) Cap(threshold int) types.Transactions {
160160
// Otherwise gather and drop the highest nonce'd transactions
161161
var drops types.Transactions
162162

163-
sort.Sort(*m.index)
164163
for size := len(m.items); size > threshold; size-- {
165-
drops = append(drops, m.items[(*m.index)[size-1]])
166-
delete(m.items, (*m.index)[size-1])
164+
dropIdx := m.index.Pop().(uint64)
165+
drops = append(drops, m.items[dropIdx])
166+
delete(m.items, dropIdx)
167167
}
168-
*m.index = (*m.index)[:threshold]
169168

170169
// If we had a cache, shift the back
171170
m.cacheMu.Lock()

0 commit comments

Comments
 (0)