QString: add needsReallocate() static helper
Split it out from resize(), will be reused in do_replace_helper(). Change-Id: If779e03196678e1618f0ecc114448fed796b43d8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
6f2a1430c9
commit
e3ae2a505e
|
|
@ -2627,6 +2627,12 @@ QString::QString(QChar ch)
|
|||
\internal
|
||||
*/
|
||||
|
||||
static bool needsReallocate(const QString &str, qsizetype newSize)
|
||||
{
|
||||
const auto capacityAtEnd = str.capacity() - str.data_ptr().freeSpaceAtBegin();
|
||||
return newSize > capacityAtEnd;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the size of the string to \a size characters.
|
||||
|
||||
|
|
@ -2663,8 +2669,7 @@ void QString::resize(qsizetype size)
|
|||
if (size < 0)
|
||||
size = 0;
|
||||
|
||||
const auto capacityAtEnd = capacity() - d.freeSpaceAtBegin();
|
||||
if (d->needsDetach() || size > capacityAtEnd)
|
||||
if (d->needsDetach() || needsReallocate(*this, size))
|
||||
reallocData(size, QArrayData::Grow);
|
||||
d.size = size;
|
||||
if (d->allocatedCapacity())
|
||||
|
|
|
|||
Loading…
Reference in New Issue