Skip to content

Commit e241a63

Browse files
committed
Clarify prevector::erase and avoid swap-to-clear
1 parent 400fdd0 commit e241a63

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/prevector.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ class prevector {
387387
}
388388

389389
iterator erase(iterator first, iterator last) {
390+
// Erase is not allowed to the change the object's capacity. That means
391+
// that when starting with an indirectly allocated prevector with
392+
// size and capacity > N, the result may be a still indirectly allocated
393+
// prevector with size <= N and capacity > N. A shrink_to_fit() call is
394+
// necessary to switch to the (more efficient) directly allocated
395+
// representation (with capacity N and size <= N).
390396
iterator p = first;
391397
char* endp = (char*)&(*end());
392398
if (!std::is_trivially_destructible<T>::value) {

src/script/script.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,9 @@ class CScript : public CScriptBase
642642

643643
void clear()
644644
{
645-
// The default std::vector::clear() does not release memory.
646-
CScriptBase().swap(*this);
645+
// The default prevector::clear() does not release memory
646+
CScriptBase::clear();
647+
shrink_to_fit();
647648
}
648649
};
649650

0 commit comments

Comments
 (0)