Skip to content

Commit

Permalink
Optimize string usage
Browse files Browse the repository at this point in the history
Use QStringBuilder more.
Use QL1S directly, without QString construction.

Change-Id: Iad844391367681fc1013b9725403d009e7c346e6
Reviewed-by: Edward Welbourne <[email protected]>
  • Loading branch information
Anton Kudryavtsev committed Jul 15, 2016
1 parent 120ba68 commit e46e112
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/corelib/kernel/qmetaobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ static inline QByteArray findMethodCandidates(const QMetaObject *metaObject, con
for (int i = 0; i < metaObject->methodCount(); ++i) {
const QMetaMethod method = metaObject->method(i);
if (method.name() == memberByteArray)
candidateMessage.append(" " + method.methodSignature() + '\n');
candidateMessage += " " + method.methodSignature() + '\n';
}
if (!candidateMessage.isEmpty()) {
candidateMessage.prepend("\nCandidates are:\n");
Expand Down
2 changes: 1 addition & 1 deletion src/gui/text/qtextdocumentfragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ QTextHtmlImporter::QTextHtmlImporter(QTextDocument *_doc, const QString &_html,
QString html = _html;
const int startFragmentPos = html.indexOf(QLatin1String("<!--StartFragment-->"));
if (startFragmentPos != -1) {
QString qt3RichTextHeader(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />"));
const QLatin1String qt3RichTextHeader("<meta name=\"qrichtext\" content=\"1\" />");

// Hack for Qt3
const bool hasQtRichtextMetaTag = html.contains(qt3RichTextHeader);
Expand Down
4 changes: 1 addition & 3 deletions src/gui/text/qtexthtmlparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1438,9 +1438,7 @@ static void setWidthAttribute(QTextLength *width, const QString &valueStr)
#ifndef QT_NO_CSSPARSER
void QTextHtmlParserNode::parseStyleAttribute(const QString &value, const QTextDocument *resourceProvider)
{
QString css = value;
css.prepend(QLatin1String("* {"));
css.append(QLatin1Char('}'));
const QString css = QLatin1String("* {") + value + QLatin1Char('}');
QCss::Parser parser(css);
QCss::StyleSheet sheet;
parser.parse(&sheet, Qt::CaseInsensitive);
Expand Down
9 changes: 3 additions & 6 deletions src/network/access/qnetworkaccessftpbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ void QNetworkAccessFtpBackend::ftpDone()
state = CheckingFeatures;
if (operation() == QNetworkAccessManager::GetOperation) {
// 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
} else {
ftpDone();
Expand All @@ -316,14 +314,13 @@ void QNetworkAccessFtpBackend::ftpDone()
state = Statting;
if (operation() == QNetworkAccessManager::GetOperation) {
// logged in successfully, send the stat requests (if supported)
QString command = url().path();
command.prepend(QLatin1String("%1 "));
const QString path = url().path();
if (supportsSize) {
ftp->rawCommand(QLatin1String("TYPE I"));
sizeId = ftp->rawCommand(command.arg(QLatin1String("SIZE"))); // get size
sizeId = ftp->rawCommand(QLatin1String("SIZE ") + path); // get size
}
if (supportsMdtm)
mdtmId = ftp->rawCommand(command.arg(QLatin1String("MDTM"))); // get modified time
mdtmId = ftp->rawCommand(QLatin1String("MDTM ") + path); // get modified time
if (!supportsSize && !supportsMdtm)
ftpDone(); // no commands sent, move to the next state
} else {
Expand Down
78 changes: 35 additions & 43 deletions src/tools/uic/cpp/cppwriteinitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,14 @@ void WriteInitialization::writeProperties(const QString &varName,
QString setFunction;

if (stdset) {
setFunction = QLatin1String("->set");
setFunction += propertyName.left(1).toUpper();
setFunction += propertyName.mid(1);
setFunction += QLatin1Char('(');
setFunction = QLatin1String("->set")
+ propertyName.left(1).toUpper()
+ propertyName.midRef(1)
+ QLatin1Char('(');
} else {
setFunction = QLatin1String("->setProperty(\"");
setFunction += propertyName;
setFunction += QLatin1String("\", QVariant");
setFunction += QLatin1String("->setProperty(\"")
+ propertyName
+ QLatin1String("\", QVariant");
if (p->kind() == DomProperty::Enum)
setFunction += QLatin1String("::fromValue");
setFunction += QLatin1Char('(');
Expand All @@ -1286,9 +1286,9 @@ void WriteInitialization::writeProperties(const QString &varName,
if (stdset)
propertyValue = fixString(p->elementCstring(), m_dindent);
else {
propertyValue = QLatin1String("QByteArray(");
propertyValue += fixString(p->elementCstring(), m_dindent);
propertyValue += QLatin1Char(')');
propertyValue = QLatin1String("QByteArray(")
+ fixString(p->elementCstring(), m_dindent)
+ QLatin1Char(')');
}
}
break;
Expand All @@ -1304,11 +1304,8 @@ void WriteInitialization::writeProperties(const QString &varName,
break;
case DomProperty::Enum:
propertyValue = p->elementEnum();
if (!propertyValue.contains(QLatin1String("::"))) {
QString scope = className;
scope += QLatin1String("::");
propertyValue.prepend(scope);
}
if (!propertyValue.contains(QLatin1String("::")))
propertyValue = className + QLatin1String("::") + propertyValue;
break;
case DomProperty::Set:
propertyValue = p->elementSet();
Expand Down Expand Up @@ -1898,31 +1895,29 @@ QString WriteInitialization::pixCall(const QString &t, const QString &text) cons
if (m_option.extractImages) {
const QString format = image->elementData()->attributeFormat();
const QString extension = format.left(format.indexOf(QLatin1Char('.'))).toLower();
QString rc = QLatin1String("QPixmap(QString::fromUtf8(\":/");
rc += m_generatedClass;
rc += QLatin1String("/images/");
rc += text;
rc += QLatin1Char('.');
rc += extension;
rc += QLatin1String("\"))");
return rc;
}
QString rc = WriteIconInitialization::iconFromDataFunction();
rc += QLatin1Char('(');
rc += text;
rc += QLatin1String("_ID)");
return rc;
return QLatin1String("QPixmap(QString::fromUtf8(\":/")
+ m_generatedClass
+ QLatin1String("/images/")
+ text
+ QLatin1Char('.')
+ extension
+ QLatin1String("\"))");
}
return WriteIconInitialization::iconFromDataFunction()
+ QLatin1Char('(')
+ text
+ QLatin1String("_ID)");
}

QString pixFunc = m_uic->pixmapFunction();
if (pixFunc.isEmpty())
pixFunc = QLatin1String("QString::fromUtf8");

type += QLatin1Char('(');
type += pixFunc;
type += QLatin1Char('(');
type += fixString(text, m_dindent);
type += QLatin1String("))");
type += QLatin1Char('(')
+ pixFunc
+ QLatin1Char('(')
+ fixString(text, m_dindent)
+ QLatin1String("))");
return type;
}

Expand Down Expand Up @@ -2316,23 +2311,20 @@ QString WriteInitialization::trCall(const QString &str, const QString &commentHi

if (m_option.translateFunction.isEmpty()) {
if (m_option.idBased) {
result = QLatin1String("qtTrId(");
result += QLatin1String("qtTrId(");
} else {
result = QLatin1String("QApplication::translate(\"");
result += m_generatedClass;
result += QLatin1Char('"');
result += QLatin1String(", ");
result += QLatin1String("QApplication::translate(\"")
+ m_generatedClass
+ QLatin1String("\", ");
}
} else {
result = m_option.translateFunction;
result += QLatin1Char('(');
result += m_option.translateFunction + QLatin1Char('(');
}

result += fixString(str, m_dindent);

if (!m_option.idBased) {
result += QLatin1String(", ");
result += comment;
result += QLatin1String(", ") + comment;
}

result += QLatin1Char(')');
Expand Down
5 changes: 2 additions & 3 deletions src/widgets/widgets/qspinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,8 @@ QString QSpinBox::textFromValue(int value) const
QString str;

if (d->displayIntegerBase != 10) {
str = QString::number(qAbs(value), d->displayIntegerBase);
if (value < 0)
str.prepend('-');
const QLatin1String prefix = value < 0 ? QLatin1String("-") : QLatin1String();
str = prefix + QString::number(qAbs(value), d->displayIntegerBase);
} else {
str = locale().toString(value);
if (!d->showGroupSeparator && (qAbs(value) >= 1000 || value == INT_MIN)) {
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/widgets/qwidgettextcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2641,8 +2641,8 @@ void QWidgetTextControl::insertFromMimeData(const QMimeData *source)
#ifndef QT_NO_TEXTHTMLPARSER
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).
QString richtext = QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));
richtext.prepend(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />"));
const QString richtext = QLatin1String("<meta name=\"qrichtext\" content=\"1\" />")
+ QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));
fragment = QTextDocumentFragment::fromHtml(richtext, d->doc);
hasData = true;
} else if (source->hasHtml() && d->acceptRichText) {
Expand Down

0 comments on commit e46e112

Please sign in to comment.