BLI: improve Vector.remove_and_reorder

The old version was correct as well but did a move even when not necessary.
This commit is contained in:
Jacques Lucke 2021-04-28 10:27:49 +02:00
parent 8a41a12c71
commit d71f96073f
1 changed files with 5 additions and 4 deletions

View File

@ -740,11 +740,12 @@ class Vector {
BLI_assert(index >= 0);
BLI_assert(index < this->size());
T *element_to_remove = begin_ + index;
if (element_to_remove < end_) {
*element_to_remove = std::move(*(end_ - 1));
T *last_element = end_ - 1;
if (element_to_remove < last_element) {
*element_to_remove = std::move(*last_element);
}
end_--;
end_->~T();
end_ = last_element;
last_element->~T();
UPDATE_VECTOR_SIZE(this);
}