Changed C++'s SharedVector::clear() to not preserve capacity when shared

This commit is contained in:
Simon Hausmann 2021-08-12 12:09:40 +02:00 committed by Simon Hausmann
parent d65af654d7
commit a752c798b8
2 changed files with 8 additions and 6 deletions

View file

@ -130,10 +130,9 @@ struct SharedVector
/// Clears the vector and removes all elements. The capacity remains unaffected.
void clear()
{
// Detach first to retain capacity, so that the begin() call doesn't detach
// (which it would to inner->size instead of capacity)
detach(inner->capacity);
{
if (inner->refcount != 1) {
*this = SharedVector();
} else {
auto b = begin(), e = end();
inner->size = 0;
for (auto it = b; it < e; ++it) {