scan the earliest items at first

This commit is contained in:
maskpp 2024-07-01 15:35:19 +08:00
parent 20f6b7a854
commit 6bd0ed9089

View file

@ -79,7 +79,8 @@ func (q *payloadQueue) get(id engine.PayloadID, full bool) *engine.ExecutionPayl
q.lock.RLock() q.lock.RLock()
defer q.lock.RUnlock() defer q.lock.RUnlock()
for _, item := range q.payloads { for i := len(q.payloads) - 1; i >= 0; i-- {
item := q.payloads[i]
if item.id == id { if item.id == id {
if !full { if !full {
return item.payload.Resolve() return item.payload.Resolve()
@ -95,7 +96,8 @@ func (q *payloadQueue) has(id engine.PayloadID) bool {
q.lock.RLock() q.lock.RLock()
defer q.lock.RUnlock() defer q.lock.RUnlock()
for _, item := range q.payloads { for i := len(q.payloads) - 1; i >= 0; i-- {
item := q.payloads[i]
if item.id == id { if item.id == id {
return true return true
} }
@ -144,7 +146,8 @@ func (q *headerQueue) get(hash common.Hash) *types.Header {
q.lock.RLock() q.lock.RLock()
defer q.lock.RUnlock() defer q.lock.RUnlock()
for _, item := range q.headers { for i := len(q.headers) - 1; i >= 0; i-- {
item := q.headers[i]
if item.hash == hash { if item.hash == hash {
return item.header return item.header
} }