mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
util: implement prevector's move ctor & move assignment
Using swap() was rather wasteful because it had to copy the whole direct memory data twice. Also, due to the swap() in move assignment the moved-from object might hold on to unused memory for longer than necessary.
This commit is contained in:
parent
fffc86f49f
commit
bfb9291a86
1 changed files with 10 additions and 3 deletions
|
@ -264,8 +264,10 @@ public:
|
|||
fill(item_ptr(0), other.begin(), other.end());
|
||||
}
|
||||
|
||||
prevector(prevector<N, T, Size, Diff>&& other) noexcept {
|
||||
swap(other);
|
||||
prevector(prevector<N, T, Size, Diff>&& other) noexcept
|
||||
: _union(std::move(other._union)), _size(other._size)
|
||||
{
|
||||
other._size = 0;
|
||||
}
|
||||
|
||||
prevector& operator=(const prevector<N, T, Size, Diff>& other) {
|
||||
|
@ -277,7 +279,12 @@ public:
|
|||
}
|
||||
|
||||
prevector& operator=(prevector<N, T, Size, Diff>&& other) noexcept {
|
||||
swap(other);
|
||||
if (!is_direct()) {
|
||||
free(_union.indirect_contents.indirect);
|
||||
}
|
||||
_union = std::move(other._union);
|
||||
_size = other._size;
|
||||
other._size = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue