mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-08 12:19:07 +02:00
Merge bitcoin/bitcoin#26888: net: simplify the call to vProcessMsg.splice()
dfc01ccd73e1f12698278d467c241f398da9fc7d net: simplify the call to vProcessMsg.splice() (Vasil Dimov)
Pull request description:
At the time when
```cpp
pnode->vProcessMsg.splice(pnode->vProcessMsg.end(), pnode->vRecvMsg, pnode->vRecvMsg.begin(), it);
```
is called, `it` is certainly `pnode->vRecvMsg.end()` which makes the call equivalent to:
```cpp
pnode->vProcessMsg.splice(pnode->vProcessMsg.end(), pnode->vRecvMsg, pnode->vRecvMsg.begin(), pnode->vRecvMsg.end());
```
which is equivalent to:
```cpp
pnode->vProcessMsg.splice(pnode->vProcessMsg.end(), pnode->vRecvMsg);
```
Thus, use the latter. Further, maybe irrelevant, but the latter has constant complexity while the original code is `O(length of vRecvMsg)`.
ACKs for top commit:
theStack:
Code-review ACK dfc01ccd73e1f12698278d467c241f398da9fc7d
MarcoFalke:
review ACK dfc01ccd73e1f12698278d467c241f398da9fc7d 🐑
jonatack:
Light review ACK dfc01ccd73e1f12698278d467c241f398da9fc7d
Tree-SHA512: 9f4eb61d1caf4af9a61ba2f54b915fcfe406db62c58ab1ec42f736505b6792e9379a83d0458d6cc04f289edcec070b7c962f94a920ab51701c3cab103152866f
This commit is contained in:
commit
ba39ffe938
@ -1305,15 +1305,14 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
|
||||
RecordBytesRecv(nBytes);
|
||||
if (notify) {
|
||||
size_t nSizeAdded = 0;
|
||||
auto it(pnode->vRecvMsg.begin());
|
||||
for (; it != pnode->vRecvMsg.end(); ++it) {
|
||||
for (const auto& msg : pnode->vRecvMsg) {
|
||||
// vRecvMsg contains only completed CNetMessage
|
||||
// the single possible partially deserialized message are held by TransportDeserializer
|
||||
nSizeAdded += it->m_raw_message_size;
|
||||
nSizeAdded += msg.m_raw_message_size;
|
||||
}
|
||||
{
|
||||
LOCK(pnode->cs_vProcessMsg);
|
||||
pnode->vProcessMsg.splice(pnode->vProcessMsg.end(), pnode->vRecvMsg, pnode->vRecvMsg.begin(), it);
|
||||
pnode->vProcessMsg.splice(pnode->vProcessMsg.end(), pnode->vRecvMsg);
|
||||
pnode->nProcessQueueSize += nSizeAdded;
|
||||
pnode->fPauseRecv = pnode->nProcessQueueSize > nReceiveFloodSize;
|
||||
}
|
||||
|
@ -67,15 +67,14 @@ void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, Span<const uint8_t> msg_by
|
||||
assert(node.ReceiveMsgBytes(msg_bytes, complete));
|
||||
if (complete) {
|
||||
size_t nSizeAdded = 0;
|
||||
auto it(node.vRecvMsg.begin());
|
||||
for (; it != node.vRecvMsg.end(); ++it) {
|
||||
for (const auto& msg : node.vRecvMsg) {
|
||||
// vRecvMsg contains only completed CNetMessage
|
||||
// the single possible partially deserialized message are held by TransportDeserializer
|
||||
nSizeAdded += it->m_raw_message_size;
|
||||
nSizeAdded += msg.m_raw_message_size;
|
||||
}
|
||||
{
|
||||
LOCK(node.cs_vProcessMsg);
|
||||
node.vProcessMsg.splice(node.vProcessMsg.end(), node.vRecvMsg, node.vRecvMsg.begin(), it);
|
||||
node.vProcessMsg.splice(node.vProcessMsg.end(), node.vRecvMsg);
|
||||
node.nProcessQueueSize += nSizeAdded;
|
||||
node.fPauseRecv = node.nProcessQueueSize > nReceiveFloodSize;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user