summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-28 14:54:59 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-01-29 22:51:10 +0100
commit43f9ac95df95387a76713a9d84d748b6d7902f26 (patch)
treeb89de0fea6e9095114a4d57d7e9b60dc00554499
parenta494ce91718feada5d6e1192957c74fe7ab1dc94 (diff)
QAndroidFormatsInfo: fix quadratic loop (eradicates Java-style iterators)
Calling QMutableListIterator::remove() in a loop is quadratic. Use Uniform Erasure erase_if, which is linear (uses std::remove_if under the hoods). Since std::remove_if() typically runs find_if() first, we can't modify elements from within erase_if()'s predicate. Factor the modifications to the elements into a separate loop. Change-Id: I04f951d9b7e05f210876a2f4065b33035c94df7a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit 2bd1201df43a508f3f83af7b4995869fa7c4212a) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/multimedia/platform/android/qandroidformatsinfo.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/multimedia/platform/android/qandroidformatsinfo.cpp b/src/multimedia/platform/android/qandroidformatsinfo.cpp
index 21f7d636d..584c7a122 100644
--- a/src/multimedia/platform/android/qandroidformatsinfo.cpp
+++ b/src/multimedia/platform/android/qandroidformatsinfo.cpp
@@ -39,7 +39,6 @@
#include "qandroidformatsinfo_p.h"
-#include <QMutableListIterator>
#include <QtCore/qjnienvironment.h>
#include <QtCore/qjniobject.h>
#include <qcoreapplication.h>
@@ -70,15 +69,13 @@ QAndroidFormatInfo::QAndroidFormatInfo()
}
auto removeUnspecifiedValues = [](QList<CodecMap> &map) {
- QMutableListIterator<CodecMap> iter(map);
- while (iter.hasNext()) {
- CodecMap &codec = iter.next();
+ for (CodecMap &codec : map) {
codec.audio.removeAll(QMediaFormat::AudioCodec::Unspecified);
codec.video.removeAll(QMediaFormat::VideoCodec::Unspecified);
-
- if (codec.audio.size() < 1 && codec.video.size() < 1)
- iter.remove();
}
+ erase_if(map, [](const CodecMap &codec) {
+ return codec.audio.isEmpty() && codec.video.isEmpty();
+ });
};
{