diff options
author | Wladimir J. van der Laan <laanwj@protonmail.com> | 2020-05-21 17:35:05 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@protonmail.com> | 2020-05-21 17:44:03 +0200 |
commit | fed1a9043fdf802c7cf7eab1c8aab25ca1c90e8d (patch) | |
tree | 0e30acb8e24d0017242f4649f6e8b490b0616267 | |
parent | 99e5e21b38bc0a5b26a53b84b5435b7abd1a7803 (diff) | |
parent | fa8bbb1368be0f3fd9cc4446aead3f4c2188a4ab (diff) |
Merge #19020: net: Use C++11 member initialization in protocol
fa8bbb1368be0f3fd9cc4446aead3f4c2188a4ab 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 fa8bbb1368be0f3fd9cc4446aead3f4c2188a4ab
Tree-SHA512: f89f6c2fe1bbfccd92acd72c0129d43e464339ed17e95384a81ed33a1a4257dba7ecc1534c6fc8c4668f0d9ade7ba0807b57066c6c763c1b72f74fc51f40907a
-rw-r--r-- | src/compat/assumptions.h | 1 | ||||
-rw-r--r-- | src/protocol.cpp | 18 | ||||
-rw-r--r-- | src/protocol.h | 15 |
3 files changed, 8 insertions, 26 deletions
diff --git a/src/compat/assumptions.h b/src/compat/assumptions.h index 6e7b4d3ded..4b0b224c69 100644 --- a/src/compat/assumptions.h +++ b/src/compat/assumptions.h @@ -50,6 +50,7 @@ static_assert(sizeof(double) == 8, "64-bit double assumed"); // code. static_assert(sizeof(short) == 2, "16-bit short assumed"); static_assert(sizeof(int) == 4, "32-bit int assumed"); +static_assert(sizeof(unsigned) == 4, "32-bit unsigned assumed"); // Assumption: We assume size_t to be 32-bit or 64-bit. // Example(s): size_t assumed to be at least 32-bit in ecdsa_signature_parse_der_lax(...). diff --git a/src/protocol.cpp b/src/protocol.cpp index 25851e786c..e929cff110 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -147,24 +147,6 @@ void SetServiceFlagsIBDCache(bool state) { g_initial_block_download_completed = state; } - -CAddress::CAddress() : CService() -{ - Init(); -} - -CAddress::CAddress(CService ipIn, ServiceFlags nServicesIn) : CService(ipIn) -{ - Init(); - nServices = nServicesIn; -} - -void CAddress::Init() -{ - nServices = NODE_NONE; - nTime = 100000000; -} - CInv::CInv() { type = 0; diff --git a/src/protocol.h b/src/protocol.h index 0bf9f1d7b5..8092ad7c13 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -328,15 +328,15 @@ static inline bool MayHaveUsefulAddressDB(ServiceFlags services) /** A CService with information about it as peer */ class CAddress : public CService { -public: - CAddress(); - explicit CAddress(CService ipIn, ServiceFlags nServicesIn); + static constexpr uint32_t TIME_INIT{100000000}; - void Init(); +public: + CAddress() : CService{} {}; + explicit CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {}; SERIALIZE_METHODS(CAddress, obj) { - SER_READ(obj, obj.Init()); + SER_READ(obj, obj.nTime = TIME_INIT); int nVersion = s.GetVersion(); if (s.GetType() & SER_DISK) { READWRITE(nVersion); @@ -349,10 +349,9 @@ public: READWRITEAS(CService, obj); } - ServiceFlags nServices; - + ServiceFlags nServices{NODE_NONE}; // disk and network only - unsigned int nTime; + uint32_t nTime{TIME_INIT}; }; /** getdata message type flags */ |