Skip to content

Commit

Permalink
Reset on move
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Sep 25, 2021
1 parent 562d975 commit 5c8caba
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/small/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ namespace small {

if (rhs.is_external()) {
this->data_.heap_storage_.pointer_ = rhs.data_.heap_storage_.pointer_;
rhs.data_.heap_storage_.pointer_ = nullptr;
size_ = rhs.size_;
rhs.size_ = 0;
this->data_.set_capacity(rhs.data_.get_capacity());
rhs.data_.set_capacity(0);
} else {
if (should_copy_inline) {
copy_inline_trivial(rhs);
Expand Down Expand Up @@ -315,10 +317,12 @@ namespace small {
} else {
// rhs is external
this->data_.heap_storage_.pointer_ = rhs.data_.heap_storage_.pointer_;
rhs.data_.heap_storage_.pointer_ = nullptr;
// this was already reset above, so it's empty and internal.
size_ = rhs.size_;
rhs.size_ = 0;
this->data_.set_capacity(rhs.data_.get_capacity());
rhs.data_.set_capacity(0);
}
}
} else {
Expand Down

0 comments on commit 5c8caba

Please sign in to comment.