Optimize string usage

Use QStringBuilder more.
Use QL1S directly, without QString construction.

Change-Id: Iad844391367681fc1013b9725403d009e7c346e6
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Anton Kudryavtsev 2016-07-08 13:51:06 +03:00
parent 120ba68882
commit e46e112eb1
7 changed files with 44 additions and 58 deletions

View File

@ -1353,7 +1353,7 @@ static inline QByteArray findMethodCandidates(const QMetaObject *metaObject, con
for (int i = 0; i < metaObject->methodCount(); ++i) { for (int i = 0; i < metaObject->methodCount(); ++i) {
const QMetaMethod method = metaObject->method(i); const QMetaMethod method = metaObject->method(i);
if (method.name() == memberByteArray) if (method.name() == memberByteArray)
candidateMessage.append(" " + method.methodSignature() + '\n'); candidateMessage += " " + method.methodSignature() + '\n';
} }
if (!candidateMessage.isEmpty()) { if (!candidateMessage.isEmpty()) {
candidateMessage.prepend("\nCandidates are:\n"); candidateMessage.prepend("\nCandidates are:\n");

View File

@ -428,7 +428,7 @@ QTextHtmlImporter::QTextHtmlImporter(QTextDocument *_doc, const QString &_html,
QString html = _html; QString html = _html;
const int startFragmentPos = html.indexOf(QLatin1String("<!--StartFragment-->")); const int startFragmentPos = html.indexOf(QLatin1String("<!--StartFragment-->"));
if (startFragmentPos != -1) { if (startFragmentPos != -1) {
QString qt3RichTextHeader(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />")); const QLatin1String qt3RichTextHeader("<meta name=\"qrichtext\" content=\"1\" />");
// Hack for Qt3 // Hack for Qt3
const bool hasQtRichtextMetaTag = html.contains(qt3RichTextHeader); const bool hasQtRichtextMetaTag = html.contains(qt3RichTextHeader);

View File

@ -1438,9 +1438,7 @@ static void setWidthAttribute(QTextLength *width, const QString &valueStr)
#ifndef QT_NO_CSSPARSER #ifndef QT_NO_CSSPARSER
void QTextHtmlParserNode::parseStyleAttribute(const QString &value, const QTextDocument *resourceProvider) void QTextHtmlParserNode::parseStyleAttribute(const QString &value, const QTextDocument *resourceProvider)
{ {
QString css = value; const QString css = QLatin1String("* {") + value + QLatin1Char('}');
css.prepend(QLatin1String("* {"));
css.append(QLatin1Char('}'));
QCss::Parser parser(css); QCss::Parser parser(css);
QCss::StyleSheet sheet; QCss::StyleSheet sheet;
parser.parse(&sheet, Qt::CaseInsensitive); parser.parse(&sheet, Qt::CaseInsensitive);

View File

@ -306,8 +306,6 @@ void QNetworkAccessFtpBackend::ftpDone()
state = CheckingFeatures; state = CheckingFeatures;
if (operation() == QNetworkAccessManager::GetOperation) { if (operation() == QNetworkAccessManager::GetOperation) {
// send help command to find out if server supports "SIZE" and "MDTM" // send help command to find out if server supports "SIZE" and "MDTM"
QString command = url().path();
command.prepend(QLatin1String("%1 "));
helpId = ftp->rawCommand(QLatin1String("HELP")); // get supported commands helpId = ftp->rawCommand(QLatin1String("HELP")); // get supported commands
} else { } else {
ftpDone(); ftpDone();
@ -316,14 +314,13 @@ void QNetworkAccessFtpBackend::ftpDone()
state = Statting; state = Statting;
if (operation() == QNetworkAccessManager::GetOperation) { if (operation() == QNetworkAccessManager::GetOperation) {
// logged in successfully, send the stat requests (if supported) // logged in successfully, send the stat requests (if supported)
QString command = url().path(); const QString path = url().path();
command.prepend(QLatin1String("%1 "));
if (supportsSize) { if (supportsSize) {
ftp->rawCommand(QLatin1String("TYPE I")); ftp->rawCommand(QLatin1String("TYPE I"));
sizeId = ftp->rawCommand(command.arg(QLatin1String("SIZE"))); // get size sizeId = ftp->rawCommand(QLatin1String("SIZE ") + path); // get size
} }
if (supportsMdtm) if (supportsMdtm)
mdtmId = ftp->rawCommand(command.arg(QLatin1String("MDTM"))); // get modified time mdtmId = ftp->rawCommand(QLatin1String("MDTM ") + path); // get modified time
if (!supportsSize && !supportsMdtm) if (!supportsSize && !supportsMdtm)
ftpDone(); // no commands sent, move to the next state ftpDone(); // no commands sent, move to the next state
} else { } else {

View File

@ -1255,14 +1255,14 @@ void WriteInitialization::writeProperties(const QString &varName,
QString setFunction; QString setFunction;
if (stdset) { if (stdset) {
setFunction = QLatin1String("->set"); setFunction = QLatin1String("->set")
setFunction += propertyName.left(1).toUpper(); + propertyName.left(1).toUpper()
setFunction += propertyName.mid(1); + propertyName.midRef(1)
setFunction += QLatin1Char('('); + QLatin1Char('(');
} else { } else {
setFunction = QLatin1String("->setProperty(\""); setFunction += QLatin1String("->setProperty(\"")
setFunction += propertyName; + propertyName
setFunction += QLatin1String("\", QVariant"); + QLatin1String("\", QVariant");
if (p->kind() == DomProperty::Enum) if (p->kind() == DomProperty::Enum)
setFunction += QLatin1String("::fromValue"); setFunction += QLatin1String("::fromValue");
setFunction += QLatin1Char('('); setFunction += QLatin1Char('(');
@ -1286,9 +1286,9 @@ void WriteInitialization::writeProperties(const QString &varName,
if (stdset) if (stdset)
propertyValue = fixString(p->elementCstring(), m_dindent); propertyValue = fixString(p->elementCstring(), m_dindent);
else { else {
propertyValue = QLatin1String("QByteArray("); propertyValue = QLatin1String("QByteArray(")
propertyValue += fixString(p->elementCstring(), m_dindent); + fixString(p->elementCstring(), m_dindent)
propertyValue += QLatin1Char(')'); + QLatin1Char(')');
} }
} }
break; break;
@ -1304,11 +1304,8 @@ void WriteInitialization::writeProperties(const QString &varName,
break; break;
case DomProperty::Enum: case DomProperty::Enum:
propertyValue = p->elementEnum(); propertyValue = p->elementEnum();
if (!propertyValue.contains(QLatin1String("::"))) { if (!propertyValue.contains(QLatin1String("::")))
QString scope = className; propertyValue = className + QLatin1String("::") + propertyValue;
scope += QLatin1String("::");
propertyValue.prepend(scope);
}
break; break;
case DomProperty::Set: case DomProperty::Set:
propertyValue = p->elementSet(); propertyValue = p->elementSet();
@ -1898,31 +1895,29 @@ QString WriteInitialization::pixCall(const QString &t, const QString &text) cons
if (m_option.extractImages) { if (m_option.extractImages) {
const QString format = image->elementData()->attributeFormat(); const QString format = image->elementData()->attributeFormat();
const QString extension = format.left(format.indexOf(QLatin1Char('.'))).toLower(); const QString extension = format.left(format.indexOf(QLatin1Char('.'))).toLower();
QString rc = QLatin1String("QPixmap(QString::fromUtf8(\":/"); return QLatin1String("QPixmap(QString::fromUtf8(\":/")
rc += m_generatedClass; + m_generatedClass
rc += QLatin1String("/images/"); + QLatin1String("/images/")
rc += text; + text
rc += QLatin1Char('.'); + QLatin1Char('.')
rc += extension; + extension
rc += QLatin1String("\"))"); + QLatin1String("\"))");
return rc;
} }
QString rc = WriteIconInitialization::iconFromDataFunction(); return WriteIconInitialization::iconFromDataFunction()
rc += QLatin1Char('('); + QLatin1Char('(')
rc += text; + text
rc += QLatin1String("_ID)"); + QLatin1String("_ID)");
return rc;
} }
QString pixFunc = m_uic->pixmapFunction(); QString pixFunc = m_uic->pixmapFunction();
if (pixFunc.isEmpty()) if (pixFunc.isEmpty())
pixFunc = QLatin1String("QString::fromUtf8"); pixFunc = QLatin1String("QString::fromUtf8");
type += QLatin1Char('('); type += QLatin1Char('(')
type += pixFunc; + pixFunc
type += QLatin1Char('('); + QLatin1Char('(')
type += fixString(text, m_dindent); + fixString(text, m_dindent)
type += QLatin1String("))"); + QLatin1String("))");
return type; return type;
} }
@ -2316,23 +2311,20 @@ QString WriteInitialization::trCall(const QString &str, const QString &commentHi
if (m_option.translateFunction.isEmpty()) { if (m_option.translateFunction.isEmpty()) {
if (m_option.idBased) { if (m_option.idBased) {
result = QLatin1String("qtTrId("); result += QLatin1String("qtTrId(");
} else { } else {
result = QLatin1String("QApplication::translate(\""); result += QLatin1String("QApplication::translate(\"")
result += m_generatedClass; + m_generatedClass
result += QLatin1Char('"'); + QLatin1String("\", ");
result += QLatin1String(", ");
} }
} else { } else {
result = m_option.translateFunction; result += m_option.translateFunction + QLatin1Char('(');
result += QLatin1Char('(');
} }
result += fixString(str, m_dindent); result += fixString(str, m_dindent);
if (!m_option.idBased) { if (!m_option.idBased) {
result += QLatin1String(", "); result += QLatin1String(", ") + comment;
result += comment;
} }
result += QLatin1Char(')'); result += QLatin1Char(')');

View File

@ -479,9 +479,8 @@ QString QSpinBox::textFromValue(int value) const
QString str; QString str;
if (d->displayIntegerBase != 10) { if (d->displayIntegerBase != 10) {
str = QString::number(qAbs(value), d->displayIntegerBase); const QLatin1String prefix = value < 0 ? QLatin1String("-") : QLatin1String();
if (value < 0) str = prefix + QString::number(qAbs(value), d->displayIntegerBase);
str.prepend('-');
} else { } else {
str = locale().toString(value); str = locale().toString(value);
if (!d->showGroupSeparator && (qAbs(value) >= 1000 || value == INT_MIN)) { if (!d->showGroupSeparator && (qAbs(value) >= 1000 || value == INT_MIN)) {

View File

@ -2641,8 +2641,8 @@ void QWidgetTextControl::insertFromMimeData(const QMimeData *source)
#ifndef QT_NO_TEXTHTMLPARSER #ifndef QT_NO_TEXTHTMLPARSER
if (source->hasFormat(QLatin1String("application/x-qrichtext")) && d->acceptRichText) { if (source->hasFormat(QLatin1String("application/x-qrichtext")) && d->acceptRichText) {
// x-qrichtext is always UTF-8 (taken from Qt3 since we don't use it anymore). // x-qrichtext is always UTF-8 (taken from Qt3 since we don't use it anymore).
QString richtext = QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext"))); const QString richtext = QLatin1String("<meta name=\"qrichtext\" content=\"1\" />")
richtext.prepend(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />")); + QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));
fragment = QTextDocumentFragment::fromHtml(richtext, d->doc); fragment = QTextDocumentFragment::fromHtml(richtext, d->doc);
hasData = true; hasData = true;
} else if (source->hasHtml() && d->acceptRichText) { } else if (source->hasHtml() && d->acceptRichText) {