From 25fff849e8f34af6d41ff36f2891bb4099b89360 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 11 Jul 2021 19:28:35 +0200 Subject: QDirIterator: add nextFileInfo() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, next() was the only way to advance the iterator, whether the caller was ultimately interested in just the filePath() (good) or not (bad luck, had to call .fileInfo()). Add a new function, nextFileInfo(), with returns fileInfo() instead. Incidentally, the returned object has already been constructed as part of advance()ing the iterator, so the new function is faster than next() even if the result is ignored, because we're not calculating a QString result the caller may not be interested in. Use the new function around the code. Fix a couple of cases of next(); fileInfo().filePath() (just use next()'s return value) as a drive-by. [ChangeLog][QtCore][QDirIterator] Added nextFileInfo(), which is like next(), but returns fileInfo() instead of filePath(). Change-Id: I601220575961169b44139fc55b9eae6c3197afb4 Reviewed-by: MÃ¥rten Nordheim --- tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp | 12 ++++++------ tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp | 3 +-- tests/benchmarks/corelib/io/qdiriterator/main.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'tests/benchmarks/corelib/io') diff --git a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp index 3184df0d7b..e02cfb3099 100644 --- a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp +++ b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp @@ -83,9 +83,9 @@ private slots: QBENCHMARK { QDirIterator dit(testdir.path(), QDir::Files); while (dit.hasNext()) { - dit.next(); - dit.fileInfo().isDir(); - dit.fileInfo().size(); + const auto fi = dit.nextFileInfo(); + (void)fi.isDir(); + (void)fi.size(); } } } @@ -104,9 +104,9 @@ private slots: QBENCHMARK { QDirIterator dit(testdir.path()); while (dit.hasNext()) { - dit.next(); - dit.fileInfo().isDir(); - dit.fileInfo().size(); + const auto fi = dit.nextFileInfo(); + (void)fi.isDir(); + (void)fi.size(); } } } diff --git a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp b/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp index 0abf8769a6..3a7db36ea2 100644 --- a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp +++ b/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp @@ -211,9 +211,8 @@ private slots: int count = 0; QDirIterator iter(dirName, QDir::Files, QDirIterator::Subdirectories); while(iter.hasNext()) { - iter.next(); count++; - totalsize += iter.fileInfo().size(); + totalsize += iter.nextFileInfo().size(); } QCOMPARE(count, 1000); QCOMPARE(totalsize, expectedSize); diff --git a/tests/benchmarks/corelib/io/qdiriterator/main.cpp b/tests/benchmarks/corelib/io/qdiriterator/main.cpp index 8c180f8757..acf1ede368 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/main.cpp +++ b/tests/benchmarks/corelib/io/qdiriterator/main.cpp @@ -189,13 +189,13 @@ void tst_qdiriterator::diriterator() QDirIterator::Subdirectories); while (dir.hasNext()) { - dir.next(); + const auto fi = dir.nextFileInfo(); //printf("%s\n", qPrintable(dir.fileName())); 0 && printf("%d %s\n", - dir.fileInfo().isDir(), - //qPrintable(dir.fileInfo().absoluteFilePath()), + fi.isDir(), + //qPrintable(fi.absoluteFilePath()), //qPrintable(dir.path()), - qPrintable(dir.filePath())); + qPrintable(fi.filePath())); ++c; } count = c; -- cgit v1.2.3