mirror of
https://github.com/monero-project/monero.git
synced 2026-01-28 07:14:46 +01:00
Merge pull request #9851
70fe289d8 Improve move/copy/default constructor semantics for tx and block (Lee *!* Clagett)
This commit is contained in:
@@ -225,8 +225,10 @@ namespace cryptonote
|
||||
|
||||
transaction();
|
||||
transaction(const transaction &t);
|
||||
transaction(transaction &&t);
|
||||
transaction &operator=(const transaction &t);
|
||||
virtual ~transaction();
|
||||
transaction &operator=(transaction &&t);
|
||||
~transaction() = default;
|
||||
void set_null();
|
||||
void invalidate_hashes();
|
||||
bool is_hash_valid() const { return hash_valid.load(std::memory_order_acquire); }
|
||||
@@ -346,71 +348,96 @@ namespace cryptonote
|
||||
|
||||
inline transaction::transaction(const transaction &t):
|
||||
transaction_prefix(t),
|
||||
hash_valid(false),
|
||||
prunable_hash_valid(false),
|
||||
blob_size_valid(false),
|
||||
hash_valid(t.is_hash_valid()),
|
||||
prunable_hash_valid(t.is_prunable_hash_valid()),
|
||||
blob_size_valid(t.is_blob_size_valid()),
|
||||
signatures(t.signatures),
|
||||
rct_signatures(t.rct_signatures),
|
||||
hash(t.hash),
|
||||
prunable_hash(t.prunable_hash),
|
||||
blob_size(t.blob_size),
|
||||
pruned(t.pruned),
|
||||
unprunable_size(t.unprunable_size.load()),
|
||||
prefix_size(t.prefix_size.load())
|
||||
{}
|
||||
|
||||
inline transaction::transaction(transaction &&t):
|
||||
transaction_prefix(std::move(t)),
|
||||
hash_valid(t.is_hash_valid()),
|
||||
prunable_hash_valid(t.is_prunable_hash_valid()),
|
||||
blob_size_valid(t.is_blob_size_valid()),
|
||||
signatures(std::move(t.signatures)),
|
||||
rct_signatures(std::move(t.rct_signatures)),
|
||||
hash(std::move(t.hash)),
|
||||
prunable_hash(std::move(t.prunable_hash)),
|
||||
blob_size(std::move(t.blob_size)),
|
||||
pruned(t.pruned),
|
||||
unprunable_size(t.unprunable_size.load()),
|
||||
prefix_size(t.prefix_size.load())
|
||||
{
|
||||
if (t.is_hash_valid())
|
||||
{
|
||||
hash = t.hash;
|
||||
set_hash_valid(true);
|
||||
}
|
||||
if (t.is_blob_size_valid())
|
||||
{
|
||||
blob_size = t.blob_size;
|
||||
set_blob_size_valid(true);
|
||||
}
|
||||
if (t.is_prunable_hash_valid())
|
||||
{
|
||||
prunable_hash = t.prunable_hash;
|
||||
set_prunable_hash_valid(true);
|
||||
}
|
||||
t.set_null();
|
||||
}
|
||||
|
||||
inline transaction &transaction::operator=(const transaction &t)
|
||||
{
|
||||
if (this == std::addressof(t))
|
||||
return *this;
|
||||
|
||||
transaction_prefix::operator=(t);
|
||||
|
||||
set_hash_valid(false);
|
||||
set_prunable_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
set_hash_valid(t.is_hash_valid());
|
||||
set_prunable_hash_valid(t.is_prunable_hash_valid());
|
||||
set_blob_size_valid(t.is_blob_size_valid());
|
||||
signatures = t.signatures;
|
||||
rct_signatures = t.rct_signatures;
|
||||
if (t.is_hash_valid())
|
||||
{
|
||||
hash = t.hash;
|
||||
set_hash_valid(true);
|
||||
}
|
||||
if (t.is_prunable_hash_valid())
|
||||
{
|
||||
prunable_hash = t.prunable_hash;
|
||||
set_prunable_hash_valid(true);
|
||||
}
|
||||
if (t.is_blob_size_valid())
|
||||
{
|
||||
blob_size = t.blob_size;
|
||||
set_blob_size_valid(true);
|
||||
}
|
||||
hash = t.hash;
|
||||
prunable_hash = t.prunable_hash;
|
||||
blob_size = t.blob_size;
|
||||
pruned = t.pruned;
|
||||
unprunable_size = t.unprunable_size.load();
|
||||
prefix_size = t.prefix_size.load();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
transaction::transaction()
|
||||
inline transaction &transaction::operator=(transaction &&t)
|
||||
{
|
||||
set_null();
|
||||
if (this == std::addressof(t))
|
||||
return *this;
|
||||
|
||||
transaction_prefix::operator=(std::move(t));
|
||||
|
||||
set_hash_valid(t.is_hash_valid());
|
||||
set_prunable_hash_valid(t.is_prunable_hash_valid());
|
||||
set_blob_size_valid(t.is_blob_size_valid());
|
||||
signatures = std::move(t.signatures);
|
||||
rct_signatures = std::move(t.rct_signatures);
|
||||
hash = std::move(t.hash);
|
||||
prunable_hash = std::move(t.prunable_hash);
|
||||
blob_size = std::move(t.blob_size);
|
||||
pruned = std::move(t.pruned);
|
||||
unprunable_size = t.unprunable_size.load();
|
||||
prefix_size = t.prefix_size.load();
|
||||
|
||||
t.set_null();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
transaction::~transaction()
|
||||
transaction::transaction():
|
||||
transaction_prefix(),
|
||||
hash_valid(false),
|
||||
prunable_hash_valid(false),
|
||||
blob_size_valid(false),
|
||||
signatures(),
|
||||
rct_signatures{},
|
||||
hash{},
|
||||
prunable_hash{},
|
||||
blob_size(0),
|
||||
pruned(false),
|
||||
unprunable_size(0),
|
||||
prefix_size(0)
|
||||
{
|
||||
// set_null() incurs atomic fence penalties
|
||||
}
|
||||
|
||||
inline
|
||||
@@ -418,7 +445,7 @@ namespace cryptonote
|
||||
{
|
||||
transaction_prefix::set_null();
|
||||
signatures.clear();
|
||||
rct_signatures.type = rct::RCTTypeNull;
|
||||
rct_signatures = rct::rctSig{};
|
||||
set_hash_valid(false);
|
||||
set_prunable_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
@@ -479,8 +506,50 @@ namespace cryptonote
|
||||
|
||||
public:
|
||||
block(): block_header(), hash_valid(false) {}
|
||||
block(const block &b): block_header(b), hash_valid(false), miner_tx(b.miner_tx), tx_hashes(b.tx_hashes) { if (b.is_hash_valid()) { hash = b.hash; set_hash_valid(true); } }
|
||||
block &operator=(const block &b) { block_header::operator=(b); hash_valid = false; miner_tx = b.miner_tx; tx_hashes = b.tx_hashes; if (b.is_hash_valid()) { hash = b.hash; set_hash_valid(true); } return *this; }
|
||||
|
||||
block(const block &b):
|
||||
block_header(b),
|
||||
hash_valid(b.is_hash_valid()),
|
||||
miner_tx(b.miner_tx),
|
||||
tx_hashes(b.tx_hashes),
|
||||
hash(b.hash)
|
||||
{}
|
||||
block(block &&b):
|
||||
block_header(std::move(b)),
|
||||
hash_valid(b.is_hash_valid()),
|
||||
miner_tx(std::move(b.miner_tx)),
|
||||
tx_hashes(std::move(b.tx_hashes)),
|
||||
hash(std::move(b.hash))
|
||||
{
|
||||
b.miner_tx.set_null();
|
||||
b.tx_hashes.clear();
|
||||
}
|
||||
block &operator=(const block &b)
|
||||
{
|
||||
if(this != std::addressof(b))
|
||||
{
|
||||
block_header::operator=(b);
|
||||
hash_valid = b.is_hash_valid();
|
||||
miner_tx = b.miner_tx;
|
||||
tx_hashes = b.tx_hashes;
|
||||
hash = b.hash;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
block &operator=(block &&b)
|
||||
{
|
||||
if (this != std::addressof(b))
|
||||
{
|
||||
block_header::operator=(std::move(b));
|
||||
hash_valid = b.is_hash_valid();
|
||||
miner_tx = std::move(b.miner_tx);
|
||||
tx_hashes = std::move(b.tx_hashes);
|
||||
hash = std::move(b.hash);
|
||||
b.miner_tx.set_null();
|
||||
b.tx_hashes.clear();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
void invalidate_hashes() { set_hash_valid(false); }
|
||||
bool is_hash_valid() const { return hash_valid.load(std::memory_order_acquire); }
|
||||
void set_hash_valid(bool v) const { hash_valid.store(v,std::memory_order_release); }
|
||||
|
||||
Reference in New Issue
Block a user