From 84277dda00c6f43a2ebe788c5c72b9c891fb3579 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 17 Aug 2022 22:09:26 +0200 Subject: [PATCH] QDir: replace an indexed loop with all_of() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces ten LOC with int/qsizetype mismatches with two LOC with no ints in sight. For reviewers that don't know std::all_of: it's range conjunction aka universal quantifier, which means it returns true for the empty set. Task-number: QTBUG-103525 Pick-to: 6.4 6.3 6.2 Change-Id: I2423102631a66996b1faff7297c7fc365f0ffb12 Reviewed-by: Sona Kurazyan Reviewed-by: MÃ¥rten Nordheim --- src/corelib/io/qdir.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 09315f9afe..26f30fba6a 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -87,16 +87,8 @@ QDirPrivate::QDirPrivate(const QString &path, const QStringList &nameFilters_, Q { setPath(path.isEmpty() ? QString::fromLatin1(".") : path); - bool empty = nameFilters.isEmpty(); - if (!empty) { - empty = true; - for (int i = 0; i < nameFilters.size(); ++i) { - if (!nameFilters.at(i).isEmpty()) { - empty = false; - break; - } - } - } + auto isEmpty = [](const auto &e) { return e.isEmpty(); }; + const bool empty = std::all_of(nameFilters.cbegin(), nameFilters.cend(), isEmpty); if (empty) nameFilters = QStringList(QString::fromLatin1("*")); }