From 426d9b9c3ea0c28ab7e7cd065fe4ae597d58a0e9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 16 Aug 2014 13:05:31 +0200 Subject: QtIcoHandler: don't hold images in QList QImage is larger than a void*, so holding them in a QList is needlessly inefficient. Worse, the code could come to depend on the fragile property of (inefficient) QLists that references to elements therein never are invalidated. Also added a reserve() call. Change-Id: I36388f2efbc6ca025f123c30bc7f1dd312bf4ab2 Reviewed-by: Konstantin Ritt Reviewed-by: Gunnar Sletta --- src/plugins/imageformats/ico/qicohandler.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/plugins/imageformats/ico/qicohandler.cpp') diff --git a/src/plugins/imageformats/ico/qicohandler.cpp b/src/plugins/imageformats/ico/qicohandler.cpp index 4cb5e22bf7..2ddbc4519b 100644 --- a/src/plugins/imageformats/ico/qicohandler.cpp +++ b/src/plugins/imageformats/ico/qicohandler.cpp @@ -96,9 +96,9 @@ public: QImage iconAt(int index); static bool canRead(QIODevice *iodev); - static QList read(QIODevice * device); + static QVector read(QIODevice *device); - static bool write(QIODevice * device, const QList & images); + static bool write(QIODevice *device, const QVector &images); private: bool readHeader(); @@ -612,12 +612,14 @@ QImage ICOReader::iconAt(int index) \sa write() */ -QList ICOReader::read(QIODevice * device) +QVector ICOReader::read(QIODevice *device) { - QList images; + QVector images; ICOReader reader(device); - for (int i = 0; i < reader.count(); i++) + const int N = reader.count(); + images.reserve(N); + for (int i = 0; i < N; i++) images += reader.iconAt(i); return images; @@ -636,7 +638,7 @@ QList ICOReader::read(QIODevice * device) \sa read() */ -bool ICOReader::write(QIODevice * device, const QList & images) +bool ICOReader::write(QIODevice *device, const QVector &images) { bool retValue = false; @@ -849,7 +851,7 @@ bool QtIcoHandler::read(QImage *image) bool QtIcoHandler::write(const QImage &image) { QIODevice *device = QImageIOHandler::device(); - QList imgs; + QVector imgs; imgs.append(image); return ICOReader::write(device, imgs); } -- cgit v1.2.3