cc6324665e
Instead of detaching when the string is shared, or if the the insertion would cause a reallocation, create a new string and copy characters to it as needed, then swap it with "this" string. This is more efficient than detaching which would copy the whole string before inserting, as some characters would be copied multiple times. Use detachAndGrow(), otherwise QStringBuilder unitests fail: PASS : tst_QStringBuilder1::initTestCase() FAIL! : tst_QStringBuilder1::scenario() 'prepends < max_prepends' returned FALSE. () Loc: [tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp(61)] PASS : tst_QStringBuilder1::cleanupTestCase() The issue is that now when inserting, if the string is going to reallocated, we create a new string, so the freeSpaceAtBegin() optimization doesn't work the same way. void checkItWorksWithFreeSpaceAtBegin(const String &chunk, const Separator &separator) { // GIVEN: a String with freeSpaceAtBegin() and less than chunk.size() freeSpaceAtEnd() String str; int prepends = 0; const int max_prepends = 10; while (str.data_ptr().freeSpaceAtBegin() < chunk.size() && prepends++ < max_prepends) str.prepend(chunk); QVERIFY(prepends < max_prepends); ... ... each str.prepend() would have reallocated. [ChangeLog][QtCore][QString] Calling insert() on a currently shared string is now done more efficiently. Task-number: QTBUG-106186 Change-Id: I07ce8d6bde50919fdc587433e624ace9cee05be8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> |
||
---|---|---|
.github/workflows | ||
bin | ||
cmake | ||
coin | ||
config.tests | ||
dist | ||
doc | ||
examples | ||
lib | ||
libexec | ||
LICENSES | ||
mkspecs | ||
qmake | ||
src | ||
tests | ||
util | ||
.cmake.conf | ||
.gitattributes | ||
.gitignore | ||
.lgtm.yml | ||
.tag | ||
CMakeLists.txt | ||
conanfile.py | ||
config_help.txt | ||
configure | ||
configure.bat | ||
configure.cmake | ||
dependencies.yaml | ||
qt_cmdline.cmake | ||
sync.profile |