Skip to content

Commit fed1a90

Browse files
committed
Merge #19020: net: Use C++11 member initialization in protocol
fa8bbb1 net: Use C++11 member initialization in protocol (MarcoFalke) Pull request description: This change removes `Init` from the constructors and instead uses C++11 member initialization. This removes a bunch of boilerplate, makes the code easier to read. Also, C++11 member initialization avoids accidental uninitialized members. ACKs for top commit: laanwj: ACK fa8bbb1 Tree-SHA512: f89f6c2fe1bbfccd92acd72c0129d43e464339ed17e95384a81ed33a1a4257dba7ecc1534c6fc8c4668f0d9ade7ba0807b57066c6c763c1b72f74fc51f40907a
2 parents 99e5e21 + fa8bbb1 commit fed1a90

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

src/compat/assumptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static_assert(sizeof(double) == 8, "64-bit double assumed");
5050
// code.
5151
static_assert(sizeof(short) == 2, "16-bit short assumed");
5252
static_assert(sizeof(int) == 4, "32-bit int assumed");
53+
static_assert(sizeof(unsigned) == 4, "32-bit unsigned assumed");
5354

5455
// Assumption: We assume size_t to be 32-bit or 64-bit.
5556
// Example(s): size_t assumed to be at least 32-bit in ecdsa_signature_parse_der_lax(...).

src/protocol.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,6 @@ void SetServiceFlagsIBDCache(bool state) {
147147
g_initial_block_download_completed = state;
148148
}
149149

150-
151-
CAddress::CAddress() : CService()
152-
{
153-
Init();
154-
}
155-
156-
CAddress::CAddress(CService ipIn, ServiceFlags nServicesIn) : CService(ipIn)
157-
{
158-
Init();
159-
nServices = nServicesIn;
160-
}
161-
162-
void CAddress::Init()
163-
{
164-
nServices = NODE_NONE;
165-
nTime = 100000000;
166-
}
167-
168150
CInv::CInv()
169151
{
170152
type = 0;

src/protocol.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,15 @@ static inline bool MayHaveUsefulAddressDB(ServiceFlags services)
328328
/** A CService with information about it as peer */
329329
class CAddress : public CService
330330
{
331-
public:
332-
CAddress();
333-
explicit CAddress(CService ipIn, ServiceFlags nServicesIn);
331+
static constexpr uint32_t TIME_INIT{100000000};
334332

335-
void Init();
333+
public:
334+
CAddress() : CService{} {};
335+
explicit CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {};
336336

337337
SERIALIZE_METHODS(CAddress, obj)
338338
{
339-
SER_READ(obj, obj.Init());
339+
SER_READ(obj, obj.nTime = TIME_INIT);
340340
int nVersion = s.GetVersion();
341341
if (s.GetType() & SER_DISK) {
342342
READWRITE(nVersion);
@@ -349,10 +349,9 @@ class CAddress : public CService
349349
READWRITEAS(CService, obj);
350350
}
351351

352-
ServiceFlags nServices;
353-
352+
ServiceFlags nServices{NODE_NONE};
354353
// disk and network only
355-
unsigned int nTime;
354+
uint32_t nTime{TIME_INIT};
356355
};
357356

358357
/** getdata message type flags */

0 commit comments

Comments
 (0)