mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-18 04:41:36 +00:00
eth/protocols/eth: prevent allocation if the response is complete
This commit is contained in:
parent
fb1ce79543
commit
f5c228576a
1 changed files with 12 additions and 8 deletions
|
|
@ -459,15 +459,19 @@ func (p *Peer) bufferReceiptsPacket(packet *ReceiptsPacket70, backend Backend) e
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// If the request is completed, append previously collected receipts
|
// If the request is complete, append the previously collected receipts to the
|
||||||
// to the packet and remove the buffered receipts.
|
// packet and discard the buffered receipts. Also clear the cached buffer used
|
||||||
if len(buffer.list) > 0 {
|
// for storing partial responses.
|
||||||
buffer.list[len(buffer.list)-1].Append(packet.List[0])
|
|
||||||
packet.List = packet.List[1:]
|
|
||||||
}
|
|
||||||
packet.List = append(buffer.list, packet.List...)
|
|
||||||
|
|
||||||
delete(p.receiptBuffer, requestId)
|
delete(p.receiptBuffer, requestId)
|
||||||
|
|
||||||
|
// Short circuit if there is nothing cached previously
|
||||||
|
if len(buffer.list) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Aggregate the cached result into the packet
|
||||||
|
buffer.list[len(buffer.list)-1].Append(packet.List[0])
|
||||||
|
packet.List = packet.List[1:]
|
||||||
|
packet.List = append(buffer.list, packet.List...)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue