summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-02-23 22:33:55 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-03-13 07:02:14 +0000
commite5ebf95bba3ac671af70d2dac291dd0d0e860428 (patch)
tree1af68fc1770332ee6cb2376e5760b2c604ee2fbd /src/corelib
parent2379bcac3267ca4209709585a20ab65a71b2056f (diff)
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 <ritt.ks@gmail.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/mimetypes/qmimemagicrule.cpp10
-rw-r--r--src/corelib/mimetypes/qmimetypeparser.cpp4
2 files changed, 7 insertions, 7 deletions
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('"');
diff --git a/src/corelib/mimetypes/qmimetypeparser.cpp b/src/corelib/mimetypes/qmimetypeparser.cpp
index 9ed345d37e..63e8f14018 100644
--- a/src/corelib/mimetypes/qmimetypeparser.cpp
+++ b/src/corelib/mimetypes/qmimetypeparser.cpp
@@ -164,7 +164,7 @@ bool QMimeTypeParserBase::parseNumber(const QStringRef &n, int *target, QString
{
bool ok;
*target = n.toInt(&ok);
- if (!ok) {
+ if (Q_UNLIKELY(!ok)) {
*errorMessage = QLatin1String("Not a number '") + n + QLatin1String("'.");
return false;
}
@@ -325,7 +325,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
}
}
- if (reader.hasError()) {
+ if (Q_UNLIKELY(reader.hasError())) {
if (errorMessage)
*errorMessage = QString::fromLatin1("An error has been encountered at line %1 of %2: %3:").arg(reader.lineNumber()).arg(fileName, reader.errorString());
return false;