Skip to content

Commit

Permalink
Use swap instead of move in addForBlock
Browse files Browse the repository at this point in the history
Use swap instead of move in DisconnectedBlockTransactions::addForBlock
in order to avoid potential problems for reusing the parents variable
after having moved it.

Signed-off-by: Andres Correa Casablanca <andres@thirdhash.com>
  • Loading branch information
Andres Correa Casablanca committed Jan 17, 2019
1 parent f14ebdd commit 94f630c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ uint64_t CSipHasher::Finalize() const
return v0 ^ v1 ^ v2 ^ v3;
}

uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256& val)
uint64_t SipHashUint256(const uint64_t k0, const uint64_t k1, const uint256& val)
{
/* Specialized implementation for efficiency */
uint64_t d = val.GetUint64(0);
Expand Down
7 changes: 3 additions & 4 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,10 +1126,9 @@ void DisconnectedBlockTransactions::addForBlock(
// In order to make sure we keep things in topological order, we check
// if we already know of the parent of the current transaction. If so,
// we remove them from the set and then add them back.
while (parents.size() > 0) {
std::unordered_set<uint256, SaltedTxidHasher> worklist(
std::move(parents)
);
while (!parents.empty()) {
std::unordered_set<uint256, SaltedTxidHasher> worklist;
parents.swap(worklist);

for (const uint256 &txid : worklist) {
// If we do not have that txid in the set, nothing needs to be
Expand Down
2 changes: 1 addition & 1 deletion src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class SaltedTxidHasher
{
private:
/** Salt */
const uint64_t k0, k1;
uint64_t k0, k1;

public:
SaltedTxidHasher();
Expand Down

0 comments on commit 94f630c

Please sign in to comment.