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>
This commit is contained in:
parent
5d44d17127
commit
b566d670e5
@ -965,14 +965,16 @@ void QMovie::setScaledSize(const QSize &size)
|
|||||||
QList<QByteArray> QMovie::supportedFormats()
|
QList<QByteArray> QMovie::supportedFormats()
|
||||||
{
|
{
|
||||||
QList<QByteArray> list = QImageReader::supportedImageFormats();
|
QList<QByteArray> list = QImageReader::supportedImageFormats();
|
||||||
QMutableListIterator<QByteArray> it(list);
|
|
||||||
QBuffer buffer;
|
QBuffer buffer;
|
||||||
buffer.open(QIODevice::ReadOnly);
|
buffer.open(QIODevice::ReadOnly);
|
||||||
while (it.hasNext()) {
|
|
||||||
QImageReader reader(&buffer, it.next());
|
const auto doesntSupportAnimation =
|
||||||
if (!reader.supportsAnimation())
|
[&buffer](const QByteArray &format) {
|
||||||
it.remove();
|
return !QImageReader(&buffer, format).supportsAnimation();
|
||||||
}
|
};
|
||||||
|
|
||||||
|
list.erase(std::remove_if(list.begin(), list.end(), doesntSupportAnimation), list.end());
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user