diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-07 17:06:18 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-08 03:11:55 +0100 |
commit | c5a51926d618470a90430eb4b2988fc437434797 (patch) | |
tree | 677f206978b192a3eb07dfef52af25fdc8c3e4e8 /src/corelib/text/qstring.cpp | |
parent | 0b0118ef28f4482a87cf9901667e6934ab49670c (diff) |
Revert "Refine {QString, QBA}::reallocData() logic"
This reverts commit 504972f838761f79a170c22225add496e7e5af6a.
Introduced realloc failures in qdoc.
Task-number: QTBUG-88258
Change-Id: I953e8d3933085022c75068af357ec9a44ab7e984
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/text/qstring.cpp')
-rw-r--r-- | src/corelib/text/qstring.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index eed98e7c7e..32e5bb7b20 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -2504,11 +2504,12 @@ void QString::reallocData(qsizetype alloc, QArrayData::AllocationOption option) return; } - // don't use reallocate path when reducing capacity and there's free space - // at the beginning: might shift data pointer outside of allocated space - const bool cannotUseReallocate = d.freeSpaceAtBegin() > 0 && alloc < d.constAllocatedCapacity(); + // there's a case of slow reallocate path where we need to memmove the data + // before a call to ::realloc(), meaning that there's an extra "heavy" + // operation. just prefer ::malloc() branch in this case + const bool slowReallocatePath = d.freeSpaceAtBegin() > 0; - if (d->needsDetach() || cannotUseReallocate) { + if (d->needsDetach() || slowReallocatePath) { DataPointer dd(Data::allocate(alloc, option), qMin(alloc, d.size)); if (dd.size > 0) ::memcpy(dd.data(), d.data(), dd.size * sizeof(QChar)); |