Skip to content

Commit 47eb765

Browse files
committed
Serializer simplifications after IMPLEMENT_SERIALIZE overhaul
1 parent 2e731f2 commit 47eb765

File tree

7 files changed

+43
-66
lines changed

7 files changed

+43
-66
lines changed

src/core.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,12 @@ class CTransaction
257257

258258
template <typename Stream, typename Operation>
259259
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
260-
bool fRead = ser_action.ForRead();
261-
262260
READWRITE(*const_cast<int32_t*>(&this->nVersion));
263261
nVersion = this->nVersion;
264262
READWRITE(*const_cast<std::vector<CTxIn>*>(&vin));
265263
READWRITE(*const_cast<std::vector<CTxOut>*>(&vout));
266264
READWRITE(*const_cast<uint32_t*>(&nLockTime));
267-
if (fRead)
265+
if (ser_action.ForRead())
268266
UpdateHash();
269267
}
270268

@@ -346,8 +344,7 @@ class CTxOutCompressor
346344

347345
template <typename Stream, typename Operation>
348346
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
349-
bool fRead = ser_action.ForRead();
350-
if (!fRead) {
347+
if (!ser_action.ForRead()) {
351348
uint64_t nVal = CompressAmount(txout.nValue);
352349
READWRITE(VARINT(nVal));
353350
} else {

src/main.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,10 @@ class CPartialMerkleTree
424424

425425
template <typename Stream, typename Operation>
426426
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
427-
bool fRead = ser_action.ForRead();
428-
429427
READWRITE(nTransactions);
430428
READWRITE(vHash);
431429
std::vector<unsigned char> vBytes;
432-
if (fRead) {
430+
if (ser_action.ForRead()) {
433431
READWRITE(vBytes);
434432
CPartialMerkleTree &us = *(const_cast<CPartialMerkleTree*>(this));
435433
us.vBits.resize(vBytes.size() * 8);

src/netbase.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,10 @@ class CService : public CNetAddr
154154

155155
template <typename Stream, typename Operation>
156156
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
157-
bool fRead = ser_action.ForRead();
158157
READWRITE(FLATDATA(ip));
159158
unsigned short portN = htons(port);
160159
READWRITE(portN);
161-
if (fRead)
160+
if (ser_action.ForRead())
162161
port = ntohs(portN);
163162
}
164163
};

src/protocol.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,13 @@ class CAddress : public CService
8989

9090
template <typename Stream, typename Operation>
9191
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
92-
bool fRead = ser_action.ForRead();
93-
94-
CAddress* pthis = const_cast<CAddress*>(this);
95-
if (fRead)
96-
pthis->Init();
92+
if (ser_action.ForRead())
93+
Init();
9794
if (nType & SER_DISK)
9895
READWRITE(nVersion);
9996
if ((nType & SER_DISK) ||
10097
(nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
101-
READWRITE(nTime);
98+
READWRITE(nTime);
10299
READWRITE(nServices);
103100
READWRITE(*(CService*)this);
104101
}

src/qt/recentrequeststablemodel.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,15 @@ class RecentRequestEntry
2828

2929
template <typename Stream, typename Operation>
3030
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
31-
bool fRead = ser_action.ForRead();
32-
33-
RecentRequestEntry* pthis = const_cast<RecentRequestEntry*>(this);
34-
3531
unsigned int nDate = date.toTime_t();
3632

37-
READWRITE(pthis->nVersion);
38-
nVersion = pthis->nVersion;
33+
READWRITE(this->nVersion);
34+
nVersion = this->nVersion;
3935
READWRITE(id);
4036
READWRITE(nDate);
4137
READWRITE(recipient);
4238

43-
if (fRead)
39+
if (ser_action.ForRead())
4440
date = QDateTime::fromTime_t(nDate);
4541
}
4642
};

src/qt/walletmodel.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,31 @@ class SendCoinsRecipient
6363

6464
template <typename Stream, typename Operation>
6565
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
66-
bool fRead = ser_action.ForRead();
67-
68-
SendCoinsRecipient* pthis = const_cast<SendCoinsRecipient*>(this);
69-
70-
std::string sAddress = pthis->address.toStdString();
71-
std::string sLabel = pthis->label.toStdString();
72-
std::string sMessage = pthis->message.toStdString();
66+
std::string sAddress = address.toStdString();
67+
std::string sLabel = label.toStdString();
68+
std::string sMessage = message.toStdString();
7369
std::string sPaymentRequest;
74-
if (!fRead && pthis->paymentRequest.IsInitialized())
75-
pthis->paymentRequest.SerializeToString(&sPaymentRequest);
76-
std::string sAuthenticatedMerchant = pthis->authenticatedMerchant.toStdString();
70+
if (!ser_action.ForRead() && paymentRequest.IsInitialized())
71+
paymentRequest.SerializeToString(&sPaymentRequest);
72+
std::string sAuthenticatedMerchant = authenticatedMerchant.toStdString();
7773

78-
READWRITE(pthis->nVersion);
79-
nVersion = pthis->nVersion;
74+
READWRITE(this->nVersion);
75+
nVersion = this->nVersion;
8076
READWRITE(sAddress);
8177
READWRITE(sLabel);
8278
READWRITE(amount);
8379
READWRITE(sMessage);
8480
READWRITE(sPaymentRequest);
8581
READWRITE(sAuthenticatedMerchant);
8682

87-
if (fRead)
83+
if (ser_action.ForRead())
8884
{
89-
pthis->address = QString::fromStdString(sAddress);
90-
pthis->label = QString::fromStdString(sLabel);
91-
pthis->message = QString::fromStdString(sMessage);
85+
address = QString::fromStdString(sAddress);
86+
label = QString::fromStdString(sLabel);
87+
message = QString::fromStdString(sMessage);
9288
if (!sPaymentRequest.empty())
93-
pthis->paymentRequest.parse(QByteArray::fromRawData(sPaymentRequest.data(), sPaymentRequest.size()));
94-
pthis->authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant);
89+
paymentRequest.parse(QByteArray::fromRawData(sPaymentRequest.data(), sPaymentRequest.size()));
90+
authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant);
9591
}
9692
}
9793
};

src/wallet.h

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -609,21 +609,18 @@ class CWalletTx : public CMerkleTx
609609

610610
template <typename Stream, typename Operation>
611611
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
612-
bool fRead = ser_action.ForRead();
613-
614-
CWalletTx* pthis = const_cast<CWalletTx*>(this);
615-
if (fRead)
616-
pthis->Init(NULL);
612+
if (ser_action.ForRead())
613+
Init(NULL);
617614
char fSpent = false;
618615

619-
if (!fRead)
616+
if (!ser_action.ForRead())
620617
{
621-
pthis->mapValue["fromaccount"] = pthis->strFromAccount;
618+
mapValue["fromaccount"] = strFromAccount;
622619

623-
WriteOrderPos(pthis->nOrderPos, pthis->mapValue);
620+
WriteOrderPos(nOrderPos, mapValue);
624621

625622
if (nTimeSmart)
626-
pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart);
623+
mapValue["timesmart"] = strprintf("%u", nTimeSmart);
627624
}
628625

629626
READWRITE(*(CMerkleTx*)this);
@@ -636,13 +633,13 @@ class CWalletTx : public CMerkleTx
636633
READWRITE(fFromMe);
637634
READWRITE(fSpent);
638635

639-
if (fRead)
636+
if (ser_action.ForRead())
640637
{
641-
pthis->strFromAccount = pthis->mapValue["fromaccount"];
638+
strFromAccount = mapValue["fromaccount"];
642639

643-
ReadOrderPos(pthis->nOrderPos, pthis->mapValue);
640+
ReadOrderPos(nOrderPos, mapValue);
644641

645-
pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0;
642+
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
646643
}
647644

648645
mapValue.erase("fromaccount");
@@ -979,46 +976,43 @@ class CAccountingEntry
979976

980977
template <typename Stream, typename Operation>
981978
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
982-
bool fRead = ser_action.ForRead();
983-
984-
CAccountingEntry& me = *const_cast<CAccountingEntry*>(this);
985979
if (!(nType & SER_GETHASH))
986980
READWRITE(nVersion);
987981
// Note: strAccount is serialized as part of the key, not here.
988982
READWRITE(nCreditDebit);
989983
READWRITE(nTime);
990984
READWRITE(LIMITED_STRING(strOtherAccount, 65536));
991985

992-
if (!fRead)
986+
if (!ser_action.ForRead())
993987
{
994-
WriteOrderPos(nOrderPos, me.mapValue);
988+
WriteOrderPos(nOrderPos, mapValue);
995989

996990
if (!(mapValue.empty() && _ssExtra.empty()))
997991
{
998992
CDataStream ss(nType, nVersion);
999993
ss.insert(ss.begin(), '\0');
1000994
ss << mapValue;
1001995
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
1002-
me.strComment.append(ss.str());
996+
strComment.append(ss.str());
1003997
}
1004998
}
1005999

10061000
READWRITE(LIMITED_STRING(strComment, 65536));
10071001

10081002
size_t nSepPos = strComment.find("\0", 0, 1);
1009-
if (fRead)
1003+
if (ser_action.ForRead())
10101004
{
1011-
me.mapValue.clear();
1005+
mapValue.clear();
10121006
if (std::string::npos != nSepPos)
10131007
{
10141008
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion);
1015-
ss >> me.mapValue;
1016-
me._ssExtra = std::vector<char>(ss.begin(), ss.end());
1009+
ss >> mapValue;
1010+
_ssExtra = std::vector<char>(ss.begin(), ss.end());
10171011
}
1018-
ReadOrderPos(me.nOrderPos, me.mapValue);
1012+
ReadOrderPos(nOrderPos, mapValue);
10191013
}
10201014
if (std::string::npos != nSepPos)
1021-
me.strComment.erase(nSepPos);
1015+
strComment.erase(nSepPos);
10221016

10231017
mapValue.erase("n");
10241018
}

0 commit comments

Comments
 (0)