diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2022-11-26 22:54:16 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2022-12-13 14:41:29 +0200 |
commit | e3ae2a505e123ee22de0fe6e5f4aff74ee1bb933 (patch) | |
tree | 35057a0a26a565cfa9c7f112e39e2da3cd0e8d37 | |
parent | 6f2a1430c9bde188beb631d0a181850b5d6ad0ea (diff) |
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>
-rw-r--r-- | src/corelib/text/qstring.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index f8e3b412a8..c8c7ce395a 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -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()) |