diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-05-05 19:17:27 +0300 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-09-10 15:14:50 +0300 |
commit | b0a3cfaf53af5e7e306369d336b9d7e2763e62de (patch) | |
tree | dd5985647d5518c80bcc3f025111bee122c0abca /tests/auto/corelib/text/qstringlist | |
parent | f7ecad02647dc227c8a951637d178724bd430782 (diff) |
QStringList: optimize replaceInStrings
By first checking if the list has any matches before potentially making
it detach.
Change-Id: I7a42c2910ef6efc45033e562573414a3a9ef972e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/text/qstringlist')
-rw-r--r-- | tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp index 3a3cbd5a81..d8a3fb78df 100644 --- a/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp @@ -225,6 +225,19 @@ void tst_QStringList::replaceInStrings() list13.replaceInStrings( QString("a"), QStringView(QString("o")) ); list14 << "olpho" << "beto" << "gommo" << "epsilon"; QCOMPARE( list11, list12 ); + + QStringList list{"alpha", "beta", "gamma"}; + QStringList copy = list; + QVERIFY(!copy.isDetached()); + + // No matches, no detach + copy.replaceInStrings("z", "y"); + QVERIFY(!copy.isDetached()); + QCOMPARE(copy, list); + + copy.replaceInStrings("a", "y"); + QVERIFY(copy.isDetached()); + QCOMPARE(copy, (QStringList{"ylphy", "bety", "gymmy"})); } void tst_QStringList::contains() |