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) m_matchFunction(nullptr)
{ {
if (m_type == Invalid) 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" // Parse for offset as "1" or "1:10"
const int colonIndex = offsets.indexOf(QLatin1Char(':')); const int colonIndex = offsets.indexOf(QLatin1Char(':'));
@ -249,7 +249,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
if (m_value.isEmpty()) { if (m_value.isEmpty()) {
m_type = Invalid; m_type = Invalid;
if (errorString) if (errorString)
*errorString = QLatin1String("Invalid empty magic rule value"); *errorString = QStringLiteral("Invalid empty magic rule value");
return; return;
} }
@ -259,8 +259,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
if (!ok) { if (!ok) {
m_type = Invalid; m_type = Invalid;
if (errorString) if (errorString)
*errorString = QString::fromLatin1("Invalid magic rule value \"%1\"").arg( *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');
QString::fromLatin1(m_value));
return; return;
} }
m_numberMask = !m_mask.isEmpty() ? m_mask.toUInt(&ok, 0) : 0; // autodetect base 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")) { if (m_mask.size() < 4 || !m_mask.startsWith("0x")) {
m_type = Invalid; m_type = Invalid;
if (errorString) if (errorString)
*errorString = QString::fromLatin1("Invalid magic rule mask \"%1\"").arg( *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');
QString::fromLatin1(m_mask));
return; return;
} }
const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData( const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData(
@ -283,8 +281,7 @@ QMimeMagicRule::QMimeMagicRule(const QString &type,
if (tempMask.size() != m_pattern.size()) { if (tempMask.size() != m_pattern.size()) {
m_type = Invalid; m_type = Invalid;
if (errorString) if (errorString)
*errorString = QString::fromLatin1("Invalid magic rule mask size \"%1\"").arg( *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');
QString::fromLatin1(m_mask));
return; return;
} }
m_mask = tempMask; 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 case ParseMimeType: { // start parsing a MIME type name
const QString name = atts.value(QLatin1String(mimeTypeAttributeC)).toString(); const QString name = atts.value(QLatin1String(mimeTypeAttributeC)).toString();
if (name.isEmpty()) { if (name.isEmpty()) {
reader.raiseError(QString::fromLatin1("Missing '%1'-attribute").arg(QString::fromLatin1(mimeTypeAttributeC))); reader.raiseError(QStringLiteral("Missing 'type'-attribute"));
} else { } else {
data.name = name; data.name = name;
} }
@ -282,8 +282,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
break; break;
} }
case ParseError: case ParseError:
reader.raiseError(QString::fromLatin1("Unexpected element <%1>"). reader.raiseError(QLatin1String("Unexpected element <") + reader.name() + QLatin1Char('>'));
arg(reader.name().toString()));
break; break;
default: default:
break; break;