mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
avoid copy the whole slice
This commit is contained in:
parent
7cfff30ba3
commit
c1579c907f
1 changed files with 5 additions and 4 deletions
|
|
@ -134,11 +134,11 @@ func (q *headerQueue) put(hash common.Hash, data *types.Header) {
|
||||||
q.lock.Lock()
|
q.lock.Lock()
|
||||||
defer q.lock.Unlock()
|
defer q.lock.Unlock()
|
||||||
|
|
||||||
copy(q.headers[1:], q.headers)
|
q.headers = append(q.headers, &headerQueueItem{
|
||||||
q.headers[0] = &headerQueueItem{
|
|
||||||
hash: hash,
|
hash: hash,
|
||||||
header: data,
|
header: data,
|
||||||
}
|
})
|
||||||
|
q.headers = q.headers[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// get retrieves a previously stored header item or nil if it does not exist.
|
// get retrieves a previously stored header item or nil if it does not exist.
|
||||||
|
|
@ -146,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 == nil {
|
if item == nil {
|
||||||
return nil // no more items
|
return nil // no more items
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue