Skip to content

Commit

Permalink
prevector::swap: fix (unreached) data corruption
Browse files Browse the repository at this point in the history
swap was using an incorrect condition to determine when to apply an
optimization
(not swapping the full direct[] when swapping two indirect prevectors).

Rather than correct the optimization I'm removing it for simplicity.
Removing
this optimization minutely improves performance in the typical
(currently only)
usage of member swap(), which is swapping with a freshly
value-initialized
object.

backports bitcoin/bitcoin@a7af72a
  • Loading branch information
random-zebra committed May 17, 2020
1 parent 0e71400 commit 035760e
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/prevector.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,7 @@ class prevector {
}

void swap(prevector<N, T, Size, Diff>& other) {
if (_size & other._size & 1) {
std::swap(_union.capacity, other._union.capacity);
std::swap(_union.indirect, other._union.indirect);
} else {
std::swap(_union, other._union);
}
std::swap(_union, other._union);
std::swap(_size, other._size);
}

Expand Down

0 comments on commit 035760e

Please sign in to comment.