diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-02-23 21:53:08 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-02-24 17:14:15 +0000 |
commit | 71b106ab436f75d3467a71b1b3739ce570b62522 (patch) | |
tree | 226119c718f7050dd3d19a33ec631f93bf4f5642 /src/corelib/mimetypes/qmimemagicrule.cpp | |
parent | 215bda50f959673f076fe76cf1f95a2a5f759b2c (diff) |
QMimeTypeParser: use QStringRef more
Keep the return values of QXmlStream*::value() around as QStringRefs
for as long as possible. Avoids conversions to QString, among other
things, for:
- comparison to another string
- conversion to int
- conversion to UTF-8 or Latin-1 byte arrays
Add a pair of Q_UNLIKELY as a drive-by.
Saves ~900b in text size on optimized GCC 5.3 Linux AMD64 builds.
Change-Id: I17d440a11aeb8675979483f89e66d0a088ccc605
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/mimetypes/qmimemagicrule.cpp')
-rw-r--r-- | src/corelib/mimetypes/qmimemagicrule.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/mimetypes/qmimemagicrule.cpp b/src/corelib/mimetypes/qmimemagicrule.cpp index 09473caa78..06628fa323 100644 --- a/src/corelib/mimetypes/qmimemagicrule.cpp +++ b/src/corelib/mimetypes/qmimemagicrule.cpp @@ -238,10 +238,10 @@ QMimeMagicRule::QMimeMagicRule(const QString &type, // Parse for offset as "1" or "1:10" const int colonIndex = offsets.indexOf(QLatin1Char(':')); - const QString startPosStr = colonIndex == -1 ? offsets : offsets.mid(0, colonIndex); - const QString endPosStr = colonIndex == -1 ? offsets : offsets.mid(colonIndex + 1); - if (!QMimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString) || - !QMimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString)) { + const QStringRef startPosStr = offsets.midRef(0, colonIndex); // \ These decay to returning 'offsets' + const QStringRef endPosStr = offsets.midRef(colonIndex + 1);// / unchanged when colonIndex == -1 + if (Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)) || + Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString))) { m_type = Invalid; return; } |