Turn some sequences of x += ... statements (with x a QString) into a long...

Turn some sequences of x += ... statements (with x a QString) into a long chain of additions (for QStringBuilder)

The power of QStringBuilder only sets in if more than two strings are concatenated
before picking up the result as QString again (e.g. when assigning to a QString variable).
There are some code parts where a lot of concatenating is done, but not in one expression,
instead assigning the intermediate result to a QString var again and again, thus preventing
the advantage of QStringBuilder.

There are also a few places in the code where literal strings are concatenated using "+",
instead of having the compiler concatenate them already.

Patch optimizes the code in those two cases: by removing "+" between literal string and
turning sequences of += into a chain of +

REVIEW: 111595

thanks boud for review
parent 6c1c532d
......@@ -1439,9 +1439,9 @@ QString KexiDB::selectStatement(const KexiDB::Driver *driver,
foreach(QuerySchema* subQuery, subqueries_for_lookup_data) {
if (!s_from.isEmpty())
s_from += QLatin1String(", ");
s_from += QLatin1String("(");
s_from += selectStatement(driver, *subQuery, params, options);
s_from += QString::fromLatin1(") AS %1%2")
s_from += QLatin1Char('(') +
selectStatement(driver, *subQuery, params, options) +
QString::fromLatin1(") AS %1%2")
.arg(kexidb_subquery_prefix).arg(subqueries_for_lookup_data_counter++);
}
sql += s_from;
......@@ -1477,8 +1477,7 @@ QString KexiDB::selectStatement(const KexiDB::Driver *driver,
escapeIdentifier(pair.second->name(), options.identifierEscaping));
}
if (rel->fieldPairs()->count() > 1) {
s_where_sub.prepend(QLatin1Char('('));
s_where_sub += QLatin1Char(')');
s_where_sub = QLatin1Char('(') + s_where_sub + QLatin1Char(')');
}
s_where += s_where_sub;
}
......
......@@ -486,13 +486,13 @@ QString Cursor::debugString() const
{
QString dbg = "CURSOR( ";
if (!m_query) {
dbg += "RAW STATEMENT: '";
dbg += m_rawStatement;
dbg += "'\n";
dbg += "RAW STATEMENT: '" +
m_rawStatement +
"'\n";
} else {
dbg += "QuerySchema: '";
dbg += m_conn->selectStatement(*m_query);
dbg += "'\n";
dbg += "QuerySchema: '" +
m_conn->selectStatement(*m_query) +
"'\n";
}
if (isOpened())
dbg += " OPENED";
......@@ -502,9 +502,9 @@ QString Cursor::debugString() const
dbg += " BUFFERED";
else
dbg += " NOT_BUFFERED";
dbg += " AT=";
dbg += QString::number((unsigned long)at());
dbg += " )";
dbg += " AT=" +
QString::number((unsigned long)at()) +
" )";
return dbg;
}
......
......@@ -169,8 +169,8 @@ QString NArgExpr::debugString()
QString s = QString("NArgExpr(")
+ "class=" + exprClassName(m_cl);
foreach(BaseExpr *expr, list) {
s += ", ";
s += expr->debugString();
s += ", " +
expr->debugString();
}
s += ')';
return s;
......
......@@ -160,8 +160,7 @@ QString FieldList::debugString() const
dbg += ",\n";
else
start = false;
dbg += " ";
dbg += field->debugString();
dbg += " " + field->debugString();
}
return dbg;
}
......
......@@ -99,7 +99,7 @@ QByteArray PreparedStatement::generateStatementString()
}
s.append(")");
s.prepend(QByteArray("INSERT INTO ") + table->name().toLatin1()
+ (allTableFieldsUsed ? "" : (" (" + namesList + ")"))
+ (allTableFieldsUsed ? "" : (" (" + namesList + ')'))
+ " VALUES (");
}
return s;
......
......@@ -900,8 +900,8 @@ QString QuerySchema::debugString() const
}
}
if (!dbg2.isEmpty()) {
dbg += "\n-BINDINGS:\n";
dbg += dbg2;
dbg += "\n-BINDINGS:\n" +
dbg2;
}
//tables
......
......@@ -1370,8 +1370,7 @@ QString KexiDB::serializeList(const QStringList &list)
// Doing it repeatedly is a pretty cheap operation.
value.reserve(4096);
value += ',';
value += QString(*it).replace('\\', "\\\\").replace(',', "\\,");
value += ',' + QString(*it).replace('\\', "\\\\").replace(',', "\\,");
}
// To be able to distinguish an empty list from a list with one empty element.
......
......@@ -397,8 +397,8 @@ public:
int selectorCount = m_selectors.count();
if (selectorCount) {
for(int i = 0; i < selectorCount-1; ++i) {
str += m_selectors[i]->toString();
str += m_combinators[i];
str += m_selectors[i]->toString() +
m_combinators[i];
}
str += m_selectors.last()->toString();
}
......
......@@ -132,12 +132,12 @@ QString KoReportHTMLCSSRenderer::renderCSS(ORODocument *document)
if (prim->type() == OROTextBox::TextBox) {
OROTextBox * tb = (OROTextBox*) prim;
style = "position: absolute; ";
style += "background-color: " + (tb->textStyle().backgroundOpacity == 0 ? "transparent" : tb->textStyle().backgroundColor.name()) + "; ";
style += "top: " + QString::number(tb->position().y()) + "pt; ";
style += "left: " + QString::number(tb->position().x()) + "pt; ";
style += "font-size: " + QString::number(tb->textStyle().font.pointSize()) + "pt; ";
style += "color: " + tb->textStyle().foregroundColor.name() + "; ";
style = "position: absolute; "
"background-color: " + (tb->textStyle().backgroundOpacity == 0 ? "transparent" : tb->textStyle().backgroundColor.name()) + "; "
"top: " + QString::number(tb->position().y()) + "pt; "
"left: " + QString::number(tb->position().x()) + "pt; "
"font-size: " + QString::number(tb->textStyle().font.pointSize()) + "pt; "
"color: " + tb->textStyle().foregroundColor.name() + "; ";
//TODO opaque text + translucent background
//it looks a pain to implement
//http://developer.mozilla.org/en/docs/Useful_CSS_tips:Color_and_Background
......@@ -149,40 +149,40 @@ QString KoReportHTMLCSSRenderer::renderCSS(ORODocument *document)
}
styleindex = styles.indexOf(style);
body += "<div class=\"style" + QString::number(styleindex) + "\">";
body += tb->text();
body += "</div>\n";
body += "<div class=\"style" + QString::number(styleindex) + "\">" +
tb->text() +
"</div>\n";
} else if (prim->type() == OROImage::Image) {
kDebug() << "Saving an image";
OROImage * im = (OROImage*) prim;
style = "position: absolute; ";
style += "top: " + QString::number(im->position().y()) + "pt; ";
style += "left: " + QString::number(im->position().x()) + "pt; ";
style = "position: absolute; "
"top: " + QString::number(im->position().y()) + "pt; "
"left: " + QString::number(im->position().x()) + "pt; ";
if (!styles.contains(style)) {
styles << style;
}
styleindex = styles.indexOf(style);
body += "<div class=\"style" + QString::number(styleindex) + "\">";
body += "<img width=\"" + QString::number(im->size().width()) + "px" + "\" height=\"" + QString::number(im->size().height()) + "px" + "\" src=\"./" + m_actualDirName + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>";
body += "</div>\n";
body += "<div class=\"style" + QString::number(styleindex) + "\">"
"<img width=\"" + QString::number(im->size().width()) + "px" + "\" height=\"" + QString::number(im->size().height()) + "px" + "\" src=\"./" + m_actualDirName + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>"
"</div>\n";
im->image().save(m_tempDirName + "/object" + QString::number(s) + QString::number(i) + ".png");
} else if (prim->type() == OROPicture::Picture) {
kDebug() << "Saving a picture";
OROPicture * im = (OROPicture*) prim;
style = "position: absolute; ";
style += "top: " + QString::number(im->position().y()) + "pt; ";
style += "left: " + QString::number(im->position().x()) + "pt; ";
style = "position: absolute; "
"top: " + QString::number(im->position().y()) + "pt; "
"left: " + QString::number(im->position().x()) + "pt; ";
if (!styles.contains(style)) {
styles << style;
}
styleindex = styles.indexOf(style);
body += "<div class=\"style" + QString::number(styleindex) + "\">";
body += "<img width=\"" + QString::number(im->size().width()) + "px" + "\" height=\"" + QString::number(im->size().height()) + "px" + "\" src=\"./" + m_actualDirName + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>";
body += "</div>\n";
body += "<div class=\"style" + QString::number(styleindex) + "\">"
"<img width=\"" + QString::number(im->size().width()) + "px" + "\" height=\"" + QString::number(im->size().height()) + "px" + "\" src=\"./" + m_actualDirName + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>"
"</div>\n";
QImage image(im->size().toSize(), QImage::Format_RGB32);
QPainter painter(&image);
......
......@@ -125,23 +125,23 @@ QString KoReportHTMLTableRenderer::renderTable(ORODocument *document)
if (prim->type() == OROTextBox::TextBox) {
OROTextBox * tb = (OROTextBox*) prim;
tr += "<td>";
tr += tb->text();
tr += "</td>\n";
tr += "<td>" +
tb->text() +
"</td>\n";
} else if (prim->type() == OROImage::Image) {
kDebug() << "Saving an image";
OROImage * im = (OROImage*) prim;
tr += "<td>";
tr += "<img src=\"./" + m_actualDirName + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>";
tr += "</td>\n";
tr += "<td>"
"<img src=\"./" + m_actualDirName + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>"
"</td>\n";
im->image().save(m_tempDirName + "/object" + QString::number(s) + QString::number(i) + ".png");
} else if (prim->type() == OROPicture::Picture) {
kDebug() << "Saving a picture";
OROPicture * im = (OROPicture*) prim;
tr += "<td>";
tr += "<img src=\"./" + m_actualDirName + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>";
tr += "</td>\n";
tr += "<td>"
"<img src=\"./" + m_actualDirName + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>"
"</td>\n";
QImage image(im->size().toSize(), QImage::Format_RGB32);
QPainter painter(&image);
im->picture()->play(&painter);
......
......@@ -79,9 +79,9 @@ bool KoReportKSpreadRenderer::render(const KoReportRendererContext& context, ORO
{
kDebug() << "Saving an image";
OROImage * im = ( OROImage* ) prim;
tr += "<td>";
tr += "<img src=\"./" + fi.fileName() + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>";
tr += "</td>\n";
tr += "<td>"
"<img src=\"./" + fi.fileName() + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>"
"</td>\n";
im->image().save(saveDir + "/object" + QString::number(s) + QString::number(i) + ".png");
}
else if (prim->type() == OROPicture::Picture)
......@@ -89,9 +89,9 @@ bool KoReportKSpreadRenderer::render(const KoReportRendererContext& context, ORO
kDebug() << "Saving a picture";
OROPicture * im = ( OROPicture* ) prim;
tr += "<td>";
tr += "<img src=\"./" + fi.fileName() + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>";
tr += "</td>\n";
tr += "<td>"
"<img src=\"./" + fi.fileName() + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>"
"</td>\n";
QImage image(im->size().toSize(), QImage::Format_RGB32);
QPainter painter(&image);
im->picture()->play(&painter);
......
......@@ -95,9 +95,7 @@ QList<KoDocumentEntry> KoDocumentEntry::query(QueryFlags flags, const QString &
QList<KoDocumentEntry> lst;
QString constr;
if (!_constr.isEmpty()) {
constr = '(';
constr += _constr;
constr += ") and ";
constr = '(' + _constr + ") and ";
}
constr += " exist Library";
......
......@@ -491,9 +491,7 @@ bool KoFilterManager::filterAvailable(KoFilterEntry::Ptr entry)
//kDebug( 30500 ) <<"Checking whether" << entry->service()->name() <<" applies.";
// generate some "unique" key
QString key(entry->service()->name());
key += " - ";
key += entry->service()->library();
QString key = entry->service()->name() + " - " + entry->service()->library();
if (!m_filterAvailable.contains(key)) {
//kDebug( 30500 ) <<"Not cached, checking...";
......
......@@ -174,15 +174,15 @@ void KoRecentDocumentsPane::selectionChanged(const QModelIndex& index)
m_previewLabel->setPixmap(preview);
if (!fileItem.isNull()) {
QString details = QString("<center>%1<br>").arg(fileItem.url().path());
details += "<table border=\"0\">";
details += i18nc("File modification date and time. %1 is date time",
"<tr><td><b>Modified:</b></td><td>%1</td></tr>",
QString(fileItem.timeString(KFileItem::ModificationTime)));
details += i18nc("File access date and time. %1 is date time",
"<tr><td><b>Accessed:</b></td><td>%1</td></tr>",
QString(fileItem.timeString(KFileItem::AccessTime)));
details += "</table></center>";
QString details = QString("<center>%1<br>").arg(fileItem.url().path()) +
"<table border=\"0\">" +
i18nc("File modification date and time. %1 is date time",
"<tr><td><b>Modified:</b></td><td>%1</td></tr>",
QString(fileItem.timeString(KFileItem::ModificationTime))) +
i18nc("File access date and time. %1 is date time",
"<tr><td><b>Accessed:</b></td><td>%1</td></tr>",
QString(fileItem.timeString(KFileItem::AccessTime))) +
"</table></center>";
m_detailsLabel->setHtml(details);
} else {
m_detailsLabel->clear();
......
......@@ -172,8 +172,7 @@ void PriorityQueue<T>::dump() const
if (m_vector[ i ]->index() != i)
out += " ERROR: index out of sync. Should be " + QString::number(i) + ", is " +
QString::number(m_vector[ i ]->index()) + ". ";
out += QString::number(m_vector[ i ]->key());
out += ", ";
out += QString::number(m_vector[ i ]->key()) + ", ";
}
if (out.isEmpty())
out = "(empty)";
......
......@@ -107,8 +107,7 @@ inline QString KoStyleStack::property(const QString &nsURI, const QString &name,
{
QString fullName(name);
if (detail) {
fullName += '-';
fullName += *detail;
fullName += '-' + *detail;
}
QList<KoXmlElement>::ConstIterator it = m_stack.end();
while (it != m_stack.begin()) {
......@@ -144,8 +143,7 @@ inline bool KoStyleStack::hasProperty(const QString &nsURI, const QString &name,
{
QString fullName(name);
if (detail) {
fullName += '-';
fullName += *detail;
fullName += '-' + *detail;
}
QList<KoXmlElement>::ConstIterator it = m_stack.end();
while (it != m_stack.begin()) {
......
......@@ -397,8 +397,7 @@ void KoXmlStreamAttribute::Private::generateQName()
{
qName = reader->d->prefixes.value(qAttr->namespaceUri().toString());
prefixLen = qName.size();
qName += ':';
qName += qAttr->name();
qName += ':' + qAttr->name();
}
......
......@@ -419,9 +419,9 @@ QString KoColorConversionSystem::bestPathToDot(const QString& srcKey, const QStr
}
Path* p = findBestPath(srcNode, dstNode);
Q_ASSERT(p);
QString dot = "digraph CCS {\n";
dot += QString(" \"%1\" [color=red]\n").arg(srcNode->id());
dot += QString(" \"%1\" [color=red]\n").arg(dstNode->id());
QString dot = "digraph CCS {\n" +
QString(" \"%1\" [color=red]\n").arg(srcNode->id()) +
QString(" \"%1\" [color=red]\n").arg(dstNode->id());
foreach(Vertex* oV, d->vertexes) {
QString options;
if (p->vertexes.contains(oV)) {
......
......@@ -367,13 +367,11 @@ bool QWinMetaFile::paint(QPaintDevice* aTarget, bool absolute)
if (metaFuncTab[ idx ].method == &QWinMetaFile::noop) {
str += "UNIMPLEMENTED ";
}
str += metaFuncTab[ idx ].name;
str += " : ";
str += metaFuncTab[ idx ].name + " : ";
for (i = 0 ; i < cmd->numParm ; i++) {
param.setNum(cmd->parm[ i ]);
str += param;
str += ' ';
str += param + ' ';
}
kDebug() << str;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment