diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-02-24 00:27:11 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-02-24 08:23:38 +0000 |
commit | e6234535929c67e7fbfa1ad7ce88f37df0b68d45 (patch) | |
tree | fc5518cdb3730ef6d45a02762a3b391a946e9d6d | |
parent | 5a7165f2ea4057edaab212d61d5abaf8b3f1bd92 (diff) |
QImageReader: remove some unneeded relocations
Replace an array of pairs of pointers with an array of pairs of
arrays. Remove the unused end marker. Add a static_assert to
verify that the size of the array matches the constant all loops
use.
Also extract the common part of the mime-type name and append it when
building a QByteArray from it. This is free, as both the new
QStringBuilder expression as well as the old construction from a const
char * incur one memory allocation each.
Replace one indexed loop with ranged-for.
Results on optimized GCC 6.1.1 Linux AMD64 builds:
text -96B
data -160B
relocs -16
Change-Id: Ic23eb06bacbf70afb6f60e2fb8a140bdd3880aca
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/gui/image/qimagereader.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 4390e46fde..2f25f4dcbc 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -190,32 +190,42 @@ enum _qt_BuiltInFormatType { _qt_NoFormat = -1 }; +#if !defined(QT_NO_IMAGEFORMAT_PPM) +# define MAX_MT_SIZE 20 +#elif !defined(QT_NO_IMAGEFORMAT_XBM) || !defined(QT_NO_IMAGEFORMAT_XPM) +# define MAX_MT_SIZE 10 +#else +# define MAX_MT_SIZE 4 +#endif + struct _qt_BuiltInFormatStruct { - const char *extension; - const char *mimeType; + char extension[4]; + char mimeType[MAX_MT_SIZE]; }; +#undef MAX_MT_SIZE + static const _qt_BuiltInFormatStruct _qt_BuiltInFormats[] = { #ifndef QT_NO_IMAGEFORMAT_PNG - {"png", "image/png"}, + {"png", "png"}, #endif #ifndef QT_NO_IMAGEFORMAT_BMP - {"bmp", "image/bmp"}, + {"bmp", "bmp"}, #endif #ifndef QT_NO_IMAGEFORMAT_PPM - {"ppm", "image/x-portable-pixmap"}, - {"pgm", "image/x-portable-graymap"}, - {"pbm", "image/x-portable-bitmap"}, + {"ppm", "x-portable-pixmap"}, + {"pgm", "x-portable-graymap"}, + {"pbm", "x-portable-bitmap"}, #endif #ifndef QT_NO_IMAGEFORMAT_XBM - {"xbm", "image/x-xbitmap"}, + {"xbm", "x-xbitmap"}, #endif #ifndef QT_NO_IMAGEFORMAT_XPM - {"xpm", "image/x-xpixmap"}, + {"xpm", "x-xpixmap"}, #endif - {"", ""} }; +Q_STATIC_ASSERT(_qt_NumFormats == sizeof _qt_BuiltInFormats / sizeof *_qt_BuiltInFormats); static QImageIOHandler *createReadHandlerHelper(QIODevice *device, const QByteArray &format, @@ -1604,8 +1614,8 @@ QList<QByteArray> QImageReader::supportedMimeTypes() { QList<QByteArray> mimeTypes; mimeTypes.reserve(_qt_NumFormats); - for (int i = 0; i < _qt_NumFormats; ++i) - mimeTypes << _qt_BuiltInFormats[i].mimeType; + for (const auto &fmt : _qt_BuiltInFormats) + mimeTypes.append(QByteArrayLiteral("image/") + fmt.mimeType); #ifndef QT_NO_IMAGEFORMATPLUGIN supportedImageHandlerMimeTypes(loader(), QImageIOPlugin::CanRead, &mimeTypes); |