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>
bb10
Marc Mutz 2014-08-16 13:05:31 +02:00
parent 831a7e06c0
commit 426d9b9c3e
1 changed files with 9 additions and 7 deletions

View File

@ -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);
}