mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
common: do not pass current time as param in priority funcs (#22183)
This commit is contained in:
parent
6f19ace5e2
commit
e52587df53
2 changed files with 3 additions and 5 deletions
|
|
@ -49,7 +49,7 @@ type LazyQueue struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
PriorityCallback func(data interface{}, now mclock.AbsTime) int64 // actual priority callback
|
PriorityCallback func(data interface{}) int64 // actual priority callback
|
||||||
MaxPriorityCallback func(data interface{}, until mclock.AbsTime) int64 // estimated maximum priority callback
|
MaxPriorityCallback func(data interface{}, until mclock.AbsTime) int64 // estimated maximum priority callback
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -140,11 +140,10 @@ func (q *LazyQueue) peekIndex() int {
|
||||||
// Pop multiple times. Popped items are passed to the callback. MultiPop returns
|
// Pop multiple times. Popped items are passed to the callback. MultiPop returns
|
||||||
// when the callback returns false or there are no more items to pop.
|
// when the callback returns false or there are no more items to pop.
|
||||||
func (q *LazyQueue) MultiPop(callback func(data interface{}, priority int64) bool) {
|
func (q *LazyQueue) MultiPop(callback func(data interface{}, priority int64) bool) {
|
||||||
now := q.clock.Now()
|
|
||||||
nextIndex := q.peekIndex()
|
nextIndex := q.peekIndex()
|
||||||
for nextIndex != -1 {
|
for nextIndex != -1 {
|
||||||
data := heap.Pop(q.queue[nextIndex]).(*item).value
|
data := heap.Pop(q.queue[nextIndex]).(*item).value
|
||||||
heap.Push(q.popQueue, &item{data, q.priority(data, now)})
|
heap.Push(q.popQueue, &item{data, q.priority(data)})
|
||||||
nextIndex = q.peekIndex()
|
nextIndex = q.peekIndex()
|
||||||
for q.popQueue.Len() != 0 && (nextIndex == -1 || q.queue[nextIndex].blocks[0][0].priority < q.popQueue.blocks[0][0].priority) {
|
for q.popQueue.Len() != 0 && (nextIndex == -1 || q.queue[nextIndex].blocks[0][0].priority < q.popQueue.blocks[0][0].priority) {
|
||||||
i := heap.Pop(q.popQueue).(*item)
|
i := heap.Pop(q.popQueue).(*item)
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ type lazyItem struct {
|
||||||
index int
|
index int
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPriority(a interface{}, now mclock.AbsTime) int64 {
|
func testPriority(a interface{}) int64 {
|
||||||
return a.(*lazyItem).p
|
return a.(*lazyItem).p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +56,6 @@ func testSetIndex(a interface{}, i int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLazyQueue(t *testing.T) {
|
func TestLazyQueue(t *testing.T) {
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
clock := &mclock.Simulated{}
|
clock := &mclock.Simulated{}
|
||||||
q := NewLazyQueue(testSetIndex, testPriority, testMaxPriority, clock, testQueueRefresh)
|
q := NewLazyQueue(testSetIndex, testPriority, testMaxPriority, clock, testQueueRefresh)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue