From 4a35b05b852e6ce6102e92d67cf2edb545e1e7a4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 13 Oct 2013 23:06:00 +0200 Subject: QImageReader/Writer: replace dubious use of QSet with QList The code populated QSets with some strings and went on to copy the values to QLists. Since QSet is unordered_set, those lists were not sorted, so the code did that manually. Since QSet is a node-based container and not even an ordered one, the code pays a hefty price just for ensuring uniqueness of values prior to sorting. The new code just crams everything into lists, duplicates and all, then sorts the lists and only then removes duplicates using std::unique. Saves 3376B in text size on Linux AMD64 GCC 4.9-trunk release stripped QtGui. Change-Id: Ifee931102c01b7505c712cebf4effc37e94165b0 Reviewed-by: Friedemann Kleint --- src/gui/image/qimagewriter.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/gui/image/qimagewriter.cpp') diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp index c12dbb6544..7b8af90357 100644 --- a/src/gui/image/qimagewriter.cpp +++ b/src/gui/image/qimagewriter.cpp @@ -678,7 +678,7 @@ bool QImageWriter::supportsOption(QImageIOHandler::ImageOption option) const #ifndef QT_NO_IMAGEFORMATPLUGIN void supportedImageHandlerFormats(QFactoryLoader *loader, QImageIOPlugin::Capability cap, - QSet *result) + QList *result) { typedef QMultiMap PluginKeyMap; typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; @@ -687,6 +687,7 @@ void supportedImageHandlerFormats(QFactoryLoader *loader, const PluginKeyMapConstIterator cend = keyMap.constEnd(); int i = -1; QImageIOPlugin *plugin = 0; + result->reserve(result->size() + keyMap.size()); for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) { if (it.key() != i) { i = it.key(); @@ -694,13 +695,13 @@ void supportedImageHandlerFormats(QFactoryLoader *loader, } const QByteArray key = it.value().toLatin1(); if (plugin && (plugin->capabilities(0, key) & cap) != 0) - result->insert(key); + result->append(key); } } void supportedImageHandlerMimeTypes(QFactoryLoader *loader, QImageIOPlugin::Capability cap, - QSet *result) + QList *result) { QList metaDataList = loader->metaData(); @@ -713,7 +714,7 @@ void supportedImageHandlerMimeTypes(QFactoryLoader *loader, const int keyCount = keys.size(); for (int k = 0; k < keyCount; ++k) { if (plugin && (plugin->capabilities(0, keys.at(k).toString().toLatin1()) & cap) != 0) - result->insert(mimeTypes.at(k).toString().toLatin1()); + result->append(mimeTypes.at(k).toString().toLatin1()); } } } @@ -746,7 +747,7 @@ void supportedImageHandlerMimeTypes(QFactoryLoader *loader, */ QList QImageWriter::supportedImageFormats() { - QSet formats; + QList formats; #ifndef QT_NO_IMAGEFORMAT_BMP formats << "bmp"; #endif @@ -770,12 +771,9 @@ QList QImageWriter::supportedImageFormats() supportedImageHandlerFormats(loader(), QImageIOPlugin::CanWrite, &formats); #endif // QT_NO_IMAGEFORMATPLUGIN - QList sortedFormats; - for (QSet::ConstIterator it = formats.constBegin(); it != formats.constEnd(); ++it) - sortedFormats << *it; - - std::sort(sortedFormats.begin(), sortedFormats.end()); - return sortedFormats; + std::sort(formats.begin(), formats.end()); + formats.erase(std::unique(formats.begin(), formats.end()), formats.end()); + return formats; } /*! @@ -788,7 +786,7 @@ QList QImageWriter::supportedImageFormats() */ QList QImageWriter::supportedMimeTypes() { - QSet mimeTypes; + QList mimeTypes; #ifndef QT_NO_IMAGEFORMAT_BMP mimeTypes << "image/bmp"; #endif @@ -814,12 +812,9 @@ QList QImageWriter::supportedMimeTypes() supportedImageHandlerMimeTypes(loader(), QImageIOPlugin::CanWrite, &mimeTypes); #endif // QT_NO_IMAGEFORMATPLUGIN - QList sortedMimeTypes; - for (QSet::ConstIterator it = mimeTypes.constBegin(); it != mimeTypes.constEnd(); ++it) - sortedMimeTypes << *it; - - std::sort(sortedMimeTypes.begin(), sortedMimeTypes.end()); - return sortedMimeTypes; + std::sort(mimeTypes.begin(), mimeTypes.end()); + mimeTypes.erase(std::unique(mimeTypes.begin(), mimeTypes.end()), mimeTypes.end()); + return mimeTypes; } QT_END_NAMESPACE -- cgit v1.2.3