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.
  • Loading branch information
kazcw committed Apr 16, 2016
1 parent 4ed41a2 commit a7af72a
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 a7af72a

Please sign in to comment.