Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
void QList<T>::reserve(qsizetype asize) { // capacity() == 0 for immutable data, so this will force a detaching below if (asize <= capacity() - d.freeSpaceAtBegin()) { if (d->flags() & Data::CapacityReserved) return; // already reserved, don't shrink if (!d->isShared()) { // accept current allocation, don't shrink d->setFlag(Data::CapacityReserved); return; } } DataPointer detached(qMax(asize, size())); detached->copyAppend(d->begin(), d->end()); if (detached.d_ptr()) detached->setFlag(Data::CapacityReserved); d.swap(detached); }
If we're already detached, but we need to reallocate because we've been asked to grow, this doesn't even attempt to exploit a possible realloc() fast path (for trivially relocatable types). It also copies elements instead of moving them.