Merge #10534: Clarify prevector::erase and avoid swap-to-clear
e241a63 Clarify prevector::erase and avoid swap-to-clear (Pieter Wuille) Tree-SHA512: fa7602038feb4417158df13ee7c0351673acf38f8a824e75889710344c46a9b8d5f6059faeb521f73e48b7ad3e1a238a9e433e4b44f7c3b9085ff08ef65271fa
This commit is contained in:
parent
eef9c8ea15
commit
c1c24205b7
@ -387,6 +387,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
iterator erase(iterator first, iterator last) {
|
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;
|
iterator p = first;
|
||||||
char* endp = (char*)&(*end());
|
char* endp = (char*)&(*end());
|
||||||
if (!std::is_trivially_destructible<T>::value) {
|
if (!std::is_trivially_destructible<T>::value) {
|
||||||
|
@ -645,8 +645,9 @@ public:
|
|||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
// The default std::vector::clear() does not release memory.
|
// The default prevector::clear() does not release memory
|
||||||
CScriptBase().swap(*this);
|
CScriptBase::clear();
|
||||||
|
shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
|
Loading…
Reference in New Issue
Block a user