summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-12-03 13:47:27 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-12-03 19:58:51 +0000
commitb566d670e5d0c0313c4b935ae8ec83f7355a55ed (patch)
tree3a659a8c89924ea41035b2a736873574c4b8fb0f /src/gui
parent5d44d171274aef3d9e93cac8e958494220234151 (diff)
QMovie: fix quadratic behavior
Repeatedly calling QList::erase(it) (via QMutableListIterator::remove()) results in quadratic runtime. Use std::remove_if, which does exactly what the old code tried to do, except in linear time. Change-Id: I682e5e05f04953ae1c8788e5d66335241de39fee Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qmovie.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp
index 09cd788c61..ba27fb355b 100644
--- a/src/gui/image/qmovie.cpp
+++ b/src/gui/image/qmovie.cpp
@@ -965,14 +965,16 @@ void QMovie::setScaledSize(const QSize &size)
QList<QByteArray> QMovie::supportedFormats()
{
QList<QByteArray> list = QImageReader::supportedImageFormats();
- QMutableListIterator<QByteArray> it(list);
+
QBuffer buffer;
buffer.open(QIODevice::ReadOnly);
- while (it.hasNext()) {
- QImageReader reader(&buffer, it.next());
- if (!reader.supportsAnimation())
- it.remove();
- }
+
+ const auto doesntSupportAnimation =
+ [&buffer](const QByteArray &format) {
+ return !QImageReader(&buffer, format).supportsAnimation();
+ };
+
+ list.erase(std::remove_if(list.begin(), list.end(), doesntSupportAnimation), list.end());
return list;
}