From e5ebf95bba3ac671af70d2dac291dd0d0e860428 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 23 Feb 2016 22:33:55 +0100 Subject: QMimeTypeParser: plaster error paths with Q_UNLIKELY ... when more than a return would be executed, to prompt the compiler to move it out of the way of the normal execution path. Unexpectedly costs ~200b in text size on optimized GCC 5.3 Linux AMD64 builds. Change-Id: I0ebfb56af7c2262f64271a1b0ec46533e6000bc9 Reviewed-by: Konstantin Ritt --- src/corelib/mimetypes/qmimemagicrule.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/corelib/mimetypes/qmimemagicrule.cpp') diff --git a/src/corelib/mimetypes/qmimemagicrule.cpp b/src/corelib/mimetypes/qmimemagicrule.cpp index 528dca3ff5..a4ba93192c 100644 --- a/src/corelib/mimetypes/qmimemagicrule.cpp +++ b/src/corelib/mimetypes/qmimemagicrule.cpp @@ -233,7 +233,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type, m_mask(mask), m_matchFunction(nullptr) { - if (m_type == Invalid) + if (Q_UNLIKELY(m_type == Invalid)) *errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported"); // Parse for offset as "1" or "1:10" @@ -246,7 +246,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type, return; } - if (m_value.isEmpty()) { + if (Q_UNLIKELY(m_value.isEmpty())) { m_type = Invalid; if (errorString) *errorString = QStringLiteral("Invalid empty magic rule value"); @@ -256,7 +256,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type, if (m_type >= Host16 && m_type <= Byte) { bool ok; m_number = m_value.toUInt(&ok, 0); // autodetect base - if (!ok) { + if (Q_UNLIKELY(!ok)) { m_type = Invalid; if (errorString) *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"'); @@ -270,7 +270,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type, m_pattern = makePattern(m_value); m_pattern.squeeze(); if (!m_mask.isEmpty()) { - if (m_mask.size() < 4 || !m_mask.startsWith("0x")) { + if (Q_UNLIKELY(m_mask.size() < 4 || !m_mask.startsWith("0x"))) { m_type = Invalid; if (errorString) *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"'); @@ -278,7 +278,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type, } const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData( m_mask.constData() + 2, m_mask.size() - 2)); - if (tempMask.size() != m_pattern.size()) { + if (Q_UNLIKELY(tempMask.size() != m_pattern.size())) { m_type = Invalid; if (errorString) *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"'); -- cgit v1.2.3