Skip to content

Commit 59e1789

Browse files
committed
Merge #8330: Structure Packing Optimizations in C{,Mutable}Transaction
37495e0 Reorder C{,Mutable}Transaction for better packing (Jeremy Rubin) Pull request description: These commits revise the layout of a few key classes to eliminate padding, eliminating useless memory overhead. -This reduces CTransaction from 96 bytes to 88 bytes Tree-SHA512: 91d1fec363edebbb1f1a5b98142c767511e99d3be857148a76e31cc512c9ab3d153083fa6b46b6407974d3b88de984b436c33e8606fbb2b273d74c825195aa17
2 parents 31809d6 + 37495e0 commit 59e1789

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/primitives/transaction.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ std::string CTxOut::ToString() const
5555
}
5656

5757
CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {}
58-
CMutableTransaction::CMutableTransaction(const CTransaction& tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {}
58+
CMutableTransaction::CMutableTransaction(const CTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime) {}
5959

6060
uint256 CMutableTransaction::GetHash() const
6161
{
@@ -76,9 +76,9 @@ uint256 CTransaction::GetWitnessHash() const
7676
}
7777

7878
/* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */
79-
CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0), hash() {}
80-
CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
81-
CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
79+
CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VERSION), nLockTime(0), hash() {}
80+
CTransaction::CTransaction(const CMutableTransaction &tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
81+
CTransaction::CTransaction(CMutableTransaction &&tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
8282

8383
CAmount CTransaction::GetValueOut() const
8484
{

src/primitives/transaction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ class CTransaction
278278
// actually immutable; deserialization and assignment are implemented,
279279
// and bypass the constness. This is safe, as they update the entire
280280
// structure, including the hash.
281-
const int32_t nVersion;
282281
const std::vector<CTxIn> vin;
283282
const std::vector<CTxOut> vout;
283+
const int32_t nVersion;
284284
const uint32_t nLockTime;
285285

286286
private:
@@ -361,9 +361,9 @@ class CTransaction
361361
/** A mutable version of CTransaction. */
362362
struct CMutableTransaction
363363
{
364-
int32_t nVersion;
365364
std::vector<CTxIn> vin;
366365
std::vector<CTxOut> vout;
366+
int32_t nVersion;
367367
uint32_t nLockTime;
368368

369369
CMutableTransaction();

0 commit comments

Comments
 (0)