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>bb10
parent
2379bcac32
commit
e5ebf95bba
|
|
@ -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('"');
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue