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>
This commit is contained in:
Marc Mutz 2017-02-24 00:27:11 +01:00
parent 5a7165f2ea
commit e623453592

View File

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