From aa37e67ef7f5ff22da0ef95fb5221bc1fff9b3ca Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 6 Oct 2022 11:08:21 +0200 Subject: Port from qAsConst() to std::as_const() We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev --- .../benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp | 2 +- tests/benchmarks/corelib/io/qfile/tst_bench_qfile.cpp | 12 ++++++------ .../tst_bench_qsortfilterproxymodel.cpp | 2 +- tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp | 4 ++-- tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp | 2 +- .../sql/kernel/qsqlrecord/tst_bench_qsqlrecord.cpp | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp index 95ab82b90a..773f17a35a 100644 --- a/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp +++ b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp @@ -69,7 +69,7 @@ private slots: stack.push(line); line = prefix; - for (const QByteArray &pathElement : qAsConst(stack)) + for (const QByteArray &pathElement : std::as_const(stack)) line += pathElement; if (line.endsWith('/')) diff --git a/tests/benchmarks/corelib/io/qfile/tst_bench_qfile.cpp b/tests/benchmarks/corelib/io/qfile/tst_bench_qfile.cpp index ea25a3fa98..b7e32be259 100644 --- a/tests/benchmarks/corelib/io/qfile/tst_bench_qfile.cpp +++ b/tests/benchmarks/corelib/io/qfile/tst_bench_qfile.cpp @@ -508,13 +508,13 @@ void tst_qfile::readSmallFiles() } QBENCHMARK { - for (QFile *const file : qAsConst(fileList)) { + for (QFile *const file : std::as_const(fileList)) { while (!file->atEnd()) file->read(buffer, blockSize); } } - for (QFile *const file : qAsConst(fileList)) { + for (QFile *const file : std::as_const(fileList)) { file->close(); delete file; } @@ -530,11 +530,11 @@ void tst_qfile::readSmallFiles() } QBENCHMARK { - for (QFSFileEngine *const fse : qAsConst(fileList)) + for (QFSFileEngine *const fse : std::as_const(fileList)) while (fse->read(buffer, blockSize)) {} } - for (QFSFileEngine *const fse : qAsConst(fileList)) { + for (QFSFileEngine *const fse : std::as_const(fileList)) { fse->close(); delete fse; } @@ -547,14 +547,14 @@ void tst_qfile::readSmallFiles() fileList.append(::fopen(QFile::encodeName(tempDir.filePath(file)).constData(), "rb")); QBENCHMARK { - for (FILE *const cfile : qAsConst(fileList)) { + for (FILE *const cfile : std::as_const(fileList)) { while (!feof(cfile)) [[maybe_unused]] auto f = ::fread(buffer, blockSize, 1, cfile); ::fseek(cfile, 0, SEEK_SET); } } - for (FILE *const cfile : qAsConst(fileList)) + for (FILE *const cfile : std::as_const(fileList)) ::fclose(cfile); } break; diff --git a/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_bench_qsortfilterproxymodel.cpp b/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_bench_qsortfilterproxymodel.cpp index f6a1a01085..76576fcf69 100644 --- a/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_bench_qsortfilterproxymodel.cpp +++ b/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_bench_qsortfilterproxymodel.cpp @@ -72,7 +72,7 @@ void tst_QSortFilterProxyModel::clearFilter() { QFETCH(const int, itemCount); resizeNumberList(m_numberList, itemCount); - QStringListModel model(qAsConst(m_numberList)); + QStringListModel model(std::as_const(m_numberList)); QCOMPARE(model.rowCount(), itemCount); QSortFilterProxyModel proxy; diff --git a/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp b/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp index 7d047dcd8f..a16299250b 100644 --- a/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp +++ b/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp @@ -81,7 +81,7 @@ void tst_LanceBench::initTestCase() } std::sort(qpsFiles.begin(), qpsFiles.end()); - for (const QString& fileName : qAsConst(qpsFiles)) { + for (const QString& fileName : std::as_const(qpsFiles)) { QFile file(scriptsDir + fileName); file.open(QFile::ReadOnly); QByteArray cont = file.readAll(); @@ -237,7 +237,7 @@ void tst_LanceBench::testCoreOpenGL() void tst_LanceBench::setupTestSuite(const QStringList& blacklist) { QTest::addColumn("qpsFile"); - for (const QString &fileName : qAsConst(qpsFiles)) { + for (const QString &fileName : std::as_const(qpsFiles)) { if (blacklist.contains(fileName)) continue; QTest::newRow(fileName.toLatin1()) << fileName; diff --git a/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp b/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp index 40ef3cdd53..cccf9c703c 100644 --- a/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp @@ -670,7 +670,7 @@ void tst_QPainter::drawPixmapImage_data_helper(bool pixmaps) for (; *targetFormats != QImage::Format_Invalid; ++targetFormats) { const QImage::Format *sourceFormats = pixmaps ? pixmapFormats : sourceImageFormats; for (; *sourceFormats != QImage::Format_Invalid; ++sourceFormats) { - for (const QSize &s : qAsConst(sizes)) { + for (const QSize &s : std::as_const(sizes)) { for (int type=0; type<=3; ++type) { QString name = QString::fromLatin1("%1 on %2, (%3x%4), %5") .arg(formatNames[*sourceFormats]) diff --git a/tests/benchmarks/sql/kernel/qsqlrecord/tst_bench_qsqlrecord.cpp b/tests/benchmarks/sql/kernel/qsqlrecord/tst_bench_qsqlrecord.cpp index d1dc3aea19..ae1b92a32c 100644 --- a/tests/benchmarks/sql/kernel/qsqlrecord/tst_bench_qsqlrecord.cpp +++ b/tests/benchmarks/sql/kernel/qsqlrecord/tst_bench_qsqlrecord.cpp @@ -39,7 +39,7 @@ QTEST_MAIN(tst_QSqlRecord) void tst_QSqlRecord::initTestCase() { dbs.open(); - for (const auto &dbName : qAsConst(dbs.dbNames)) { + for (const auto &dbName : std::as_const(dbs.dbNames)) { QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); dropTestTables(db); // In case of leftovers @@ -50,7 +50,7 @@ void tst_QSqlRecord::initTestCase() void tst_QSqlRecord::cleanupTestCase() { - for (const auto &dbName : qAsConst(dbs.dbNames)) { + for (const auto &dbName : std::as_const(dbs.dbNames)) { QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); dropTestTables(db); -- cgit v1.2.3