From 1c6bf3e09ea9722717caedcfcceaaf3d607615cf Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 30 Sep 2022 14:09:04 +0200 Subject: Port from container::count() and length() to size() - V5 This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to handle typedefs and accesses through pointers, too: const std::string o = "object"; auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); }; auto derivedFromAnyOfClasses = [&](ArrayRef classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef classes, StringRef from, StringRef to) { return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)), callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))), changeTo(cat(access(o, cat(to)), "()")), cat("use '", to, "' instead of '", from, "'")); }; renameMethod(, "count", "size"); renameMethod(, "length", "size"); except that the on() matcher has been replaced by one that doesn't ignoreParens(). a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'. Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache, to avoid porting calls that explicitly test count(). Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22 Reviewed-by: Ivan Solovev Reviewed-by: Qt CI Bot --- tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp | 4 ++-- .../corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp | 2 +- tests/benchmarks/corelib/tools/qhash/outofline.cpp | 2 +- .../widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp b/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp index a1abeca12a..424ff88048 100644 --- a/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp +++ b/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp @@ -43,9 +43,9 @@ void tst_QProcess::echoTest_performance() while (stopWatch.elapsed() < 2000) { process.write(array); while (process.bytesToWrite() > 0) { - int readCount = readyReadSpy.count(); + int readCount = readyReadSpy.size(); QVERIFY(process.waitForBytesWritten(5000)); - if (readyReadSpy.count() == readCount) + if (readyReadSpy.size() == readCount) QVERIFY(process.waitForReadyRead(5000)); } diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp b/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp index 3ecc700421..0711dd9244 100644 --- a/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp +++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp @@ -56,7 +56,7 @@ void tst_QMimeDatabase::inheritsPerformance() mimeTypes += mimeTypes; mimeTypes += mimeTypes; mimeTypes += mimeTypes; - QCOMPARE(mimeTypes.count(), 40); + QCOMPARE(mimeTypes.size(), 40); QMimeDatabase db; QMimeType mime = db.mimeTypeForName(QString::fromLatin1("text/x-chdr")); QVERIFY(mime.isValid()); diff --git a/tests/benchmarks/corelib/tools/qhash/outofline.cpp b/tests/benchmarks/corelib/tools/qhash/outofline.cpp index 28c8ad6459..6ad1a4c52a 100644 --- a/tests/benchmarks/corelib/tools/qhash/outofline.cpp +++ b/tests/benchmarks/corelib/tools/qhash/outofline.cpp @@ -7,7 +7,7 @@ QT_BEGIN_NAMESPACE size_t qHash(const Qt4String &str) { - qsizetype n = str.length(); + qsizetype n = str.size(); const QChar *p = str.unicode(); uint h = 0; diff --git a/tests/benchmarks/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp b/tests/benchmarks/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp index e16d1f313b..066c981455 100644 --- a/tests/benchmarks/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp +++ b/tests/benchmarks/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp @@ -95,7 +95,7 @@ void tst_QGraphicsLayout::invalidate() QBENCHMARK { leaf->setMinimumSize(size); leaf->setMaximumSize(size); - while (setGeometryCalls->count() < depth) { + while (setGeometryCalls->size() < depth) { QApplication::sendPostedEvents(); } // force a resize on each widget, this will ensure -- cgit v1.2.3