QMimeTypeParser: use QStringBuilder more

Replace QString::arg() with QStringBuilder, use QStringLiteral
where appropriate, and remove it where it isn't (e.g. in
QStringBuilder expressions).

Saves ~750b in text size on optimized GCC 5.3 Linux AMD64 builds.

Change-Id: I2471c849db79f477677213f9a155053248800590
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2016-02-23 22:01:52 +01:00
parent 71b106ab43
commit a4dee8e274
2 changed files with 7 additions and 11 deletions

View File

@ -234,7 +234,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
m_matchFunction(nullptr)
{
if (m_type == Invalid)
*errorString = QStringLiteral("Type %s is not supported").arg(type);
*errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported");
// Parse for offset as "1" or "1:10"
const int colonIndex = offsets.indexOf(QLatin1Char(':'));
@ -249,7 +249,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
if (m_value.isEmpty()) {
m_type = Invalid;
if (errorString)
*errorString = QLatin1String("Invalid empty magic rule value");
*errorString = QStringLiteral("Invalid empty magic rule value");
return;
}
@ -259,8 +259,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
if (!ok) {
m_type = Invalid;
if (errorString)
*errorString = QString::fromLatin1("Invalid magic rule value \"%1\"").arg(
QString::fromLatin1(m_value));
*errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');
return;
}
m_numberMask = !m_mask.isEmpty() ? m_mask.toUInt(&ok, 0) : 0; // autodetect base
@ -274,8 +273,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
if (m_mask.size() < 4 || !m_mask.startsWith("0x")) {
m_type = Invalid;
if (errorString)
*errorString = QString::fromLatin1("Invalid magic rule mask \"%1\"").arg(
QString::fromLatin1(m_mask));
*errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');
return;
}
const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData(
@ -283,8 +281,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
if (tempMask.size() != m_pattern.size()) {
m_type = Invalid;
if (errorString)
*errorString = QString::fromLatin1("Invalid magic rule mask size \"%1\"").arg(
QString::fromLatin1(m_mask));
*errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');
return;
}
m_mask = tempMask;

View File

@ -205,7 +205,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
case ParseMimeType: { // start parsing a MIME type name
const QString name = atts.value(QLatin1String(mimeTypeAttributeC)).toString();
if (name.isEmpty()) {
reader.raiseError(QString::fromLatin1("Missing '%1'-attribute").arg(QString::fromLatin1(mimeTypeAttributeC)));
reader.raiseError(QStringLiteral("Missing 'type'-attribute"));
} else {
data.name = name;
}
@ -282,8 +282,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
break;
}
case ParseError:
reader.raiseError(QString::fromLatin1("Unexpected element <%1>").
arg(reader.name().toString()));
reader.raiseError(QLatin1String("Unexpected element <") + reader.name() + QLatin1Char('>'));
break;
default:
break;