diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-08-16 13:05:31 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-06-22 10:43:17 +0000 |
commit | 426d9b9c3ea0c28ab7e7cd065fe4ae597d58a0e9 (patch) | |
tree | 8e3a003a63bc5e4df2042e36d8aa726aefe118a2 /src/plugins/imageformats | |
parent | 831a7e06c0f3df5b93ae27e3535fe64188ececb6 (diff) | |
download | qtbase-426d9b9c3ea0c28ab7e7cd065fe4ae597d58a0e9.tar.gz |
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 <ritt.ks@gmail.com>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/plugins/imageformats')
-rw-r--r-- | src/plugins/imageformats/ico/qicohandler.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
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<QImage> read(QIODevice * device); + static QVector<QImage> read(QIODevice *device); - static bool write(QIODevice * device, const QList<QImage> & images); + static bool write(QIODevice *device, const QVector<QImage> &images); private: bool readHeader(); @@ -612,12 +612,14 @@ QImage ICOReader::iconAt(int index) \sa write() */ -QList<QImage> ICOReader::read(QIODevice * device) +QVector<QImage> ICOReader::read(QIODevice *device) { - QList<QImage> images; + QVector<QImage> 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<QImage> ICOReader::read(QIODevice * device) \sa read() */ -bool ICOReader::write(QIODevice * device, const QList<QImage> & images) +bool ICOReader::write(QIODevice *device, const QVector<QImage> &images) { bool retValue = false; @@ -849,7 +851,7 @@ bool QtIcoHandler::read(QImage *image) bool QtIcoHandler::write(const QImage &image) { QIODevice *device = QImageIOHandler::device(); - QList<QImage> imgs; + QVector<QImage> imgs; imgs.append(image); return ICOReader::write(device, imgs); } |