Clarify prevector::erase and avoid swap-to-clear

This commit is contained in:
Pieter Wuille 2017-06-05 12:17:40 -07:00
parent 400fdd08cc
commit e241a63c23
2 changed files with 9 additions and 2 deletions

View file

@ -387,6 +387,12 @@ public:
}
iterator erase(iterator first, iterator last) {
// Erase is not allowed to the change the object's capacity. That means
// that when starting with an indirectly allocated prevector with
// size and capacity > N, the result may be a still indirectly allocated
// prevector with size <= N and capacity > N. A shrink_to_fit() call is
// necessary to switch to the (more efficient) directly allocated
// representation (with capacity N and size <= N).
iterator p = first;
char* endp = (char*)&(*end());
if (!std::is_trivially_destructible<T>::value) {

View file

@ -642,8 +642,9 @@ public:
void clear()
{
// The default std::vector::clear() does not release memory.
CScriptBase().swap(*this);
// The default prevector::clear() does not release memory
CScriptBase::clear();
shrink_to_fit();
}
};