diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/tools/qarraydataops.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 785a26c3a86..de149b701ca 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -89,6 +89,14 @@ struct QPodArrayOps this->size += n; } + void truncate(size_t newSize) + { + Q_ASSERT(!this->ref.isShared()); + Q_ASSERT(newSize < size_t(this->size)); + + this->size = newSize; + } + void destroyAll() // Call from destructors, ONLY! { Q_ASSERT(this->ref.atomic.load() == 0); @@ -153,6 +161,17 @@ struct QGenericArrayOps } } + void truncate(size_t newSize) + { + Q_ASSERT(!this->ref.isShared()); + Q_ASSERT(newSize < size_t(this->size)); + + const T *const b = this->begin(); + do { + (b + --this->size)->~T(); + } while (uint(this->size) != newSize); + } + void destroyAll() // Call from destructors, ONLY { // As this is to be called only from destructor, it doesn't need to be @@ -239,6 +258,7 @@ struct QMovableArrayOps { // using QGenericArrayOps<T>::appendInitialize; // using QGenericArrayOps<T>::copyAppend; + // using QGenericArrayOps<T>::truncate; // using QGenericArrayOps<T>::destroyAll; void insert(T *where, const T *b, const T *e) |
