Skip to content

Commit 7588b85

Browse files
theunisipa
authored andcommitted
net: construct CNodeStates in place
1 parent 440f1d3 commit 7588b85

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ struct CBlockReject {
257257
*/
258258
struct CNodeState {
259259
//! The peer's address
260-
CService address;
260+
const CService address;
261261
//! Whether we have a fully established connection.
262262
bool fCurrentlyConnected;
263263
//! Accumulated misbehaviour score for this peer.
264264
int nMisbehavior;
265265
//! Whether this peer should be disconnected and banned (unless whitelisted).
266266
bool fShouldBan;
267267
//! String name of this peer (debugging/logging purposes).
268-
std::string name;
268+
const std::string name;
269269
//! List of asynchronously-determined block rejections to notify this peer about.
270270
std::vector<CBlockReject> rejects;
271271
//! The best known block we know this peer has announced.
@@ -309,7 +309,7 @@ struct CNodeState {
309309
*/
310310
bool fSupportsDesiredCmpctVersion;
311311

312-
CNodeState() {
312+
CNodeState(CAddress addrIn, std::string addrNameIn) : address(addrIn), name(addrNameIn) {
313313
fCurrentlyConnected = false;
314314
nMisbehavior = 0;
315315
fShouldBan = false;
@@ -355,10 +355,10 @@ void UpdatePreferredDownload(CNode* node, CNodeState* state)
355355
}
356356

357357
void InitializeNode(NodeId nodeid, const CNode *pnode) {
358+
CAddress addr = pnode->addr;
359+
std::string addrName = pnode->addrName;
358360
LOCK(cs_main);
359-
CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second;
360-
state.name = pnode->addrName;
361-
state.address = pnode->addr;
361+
mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName)));
362362
}
363363

364364
void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) {

0 commit comments

Comments
 (0)