diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-09-30 14:09:04 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-10-04 07:40:08 +0200 |
commit | df9d882d41b741fef7c5beeddb0abe9d904443d8 (patch) | |
tree | 6f3e90dacad4581b7f1cabe235cca298833a3da4 /tests/benchmarks | |
parent | 109e088c7c5d0c9325966e88d55fd9f7a58f67ea (diff) |
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/benchmarks')
3 files changed, 13 insertions, 13 deletions
diff --git a/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp b/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp index ff651eebae..c4d4265d4f 100644 --- a/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp +++ b/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp @@ -274,7 +274,7 @@ void tst_QMutex::contendedNative() NativeMutexInitialize(&mutex2); QList<NativeMutexThread *> threads(threadCount); - for (int i = 0; i < threads.count(); ++i) { + for (int i = 0; i < threads.size(); ++i) { threads[i] = new NativeMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); threads[i]->start(); } @@ -286,11 +286,11 @@ void tst_QMutex::contendedNative() semaphore4.release(threadCount); } - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->done = true; semaphore1.acquire(threadCount); semaphore2.release(threadCount); - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->wait(); qDeleteAll(threads); @@ -342,7 +342,7 @@ void tst_QMutex::contendedQMutex() QMutex mutex1, mutex2; QList<QMutexThread *> threads(threadCount); - for (int i = 0; i < threads.count(); ++i) { + for (int i = 0; i < threads.size(); ++i) { threads[i] = new QMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); threads[i]->start(); } @@ -354,11 +354,11 @@ void tst_QMutex::contendedQMutex() semaphore4.release(threadCount); } - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->done = true; semaphore1.acquire(threadCount); semaphore2.release(threadCount); - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->wait(); qDeleteAll(threads); } @@ -405,7 +405,7 @@ void tst_QMutex::contendedQMutexLocker() QMutex mutex1, mutex2; QList<QMutexLockerThread *> threads(threadCount); - for (int i = 0; i < threads.count(); ++i) { + for (int i = 0; i < threads.size(); ++i) { threads[i] = new QMutexLockerThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); threads[i]->start(); } @@ -417,11 +417,11 @@ void tst_QMutex::contendedQMutexLocker() semaphore4.release(threadCount); } - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->done = true; semaphore1.acquire(threadCount); semaphore2.release(threadCount); - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->wait(); qDeleteAll(threads); } diff --git a/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp index ca48763538..fd0a74b52a 100644 --- a/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp +++ b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp @@ -85,7 +85,7 @@ void tst_QHash::initTestCase() QByteArray id("AAAAAAA"); if (dict.isEmpty()) { - for (int i = id.length() - 1; i > 0;) { + for (int i = id.size() - 1; i > 0;) { dict.append(id); char c = id.at(i); id[i] = ++c; diff --git a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h index f29a62a8e0..03fb01f177 100644 --- a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h +++ b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h @@ -529,13 +529,13 @@ public: m_staticTexts.append(staticText); QFontMetrics fm(p->font()); - m_size = QSize(fm.horizontalAdvance(m_text, m_text.length()), fm.height()); + m_size = QSize(fm.horizontalAdvance(m_text, m_text.size()), fm.height()); break; } case PainterQPointMode: { QFontMetrics fm(p->font()); - m_size = QSize(fm.horizontalAdvance(m_text, m_text.length()), fm.height()); + m_size = QSize(fm.horizontalAdvance(m_text, m_text.size()), fm.height()); break; } @@ -576,7 +576,7 @@ public: QString name() const override { - int letters = m_text.length(); + int letters = m_text.size(); int lines = m_text.count('\n'); if (lines == 0) lines = 1; |