Optimize CppCodeMarker::addMarkUp further

This avoids a couple of more string/memory
allocations, giving another 5% speed gain
for qdoc --prepare.

Change-Id: I455f615bb4388d883dca5a8cd31bf50629db23e0
Reviewed-by: Martin Smith <martin.smith@digia.com>
This commit is contained in:
Lars Knoll 2015-07-22 15:07:21 +02:00
parent 5fd9fe02ff
commit dbf4c6290f
3 changed files with 12 additions and 15 deletions

View File

@ -194,22 +194,20 @@ QString CodeMarker::protect(const QString& str)
return marked;
}
QString CodeMarker::protect(const QStringRef& str)
void CodeMarker::appendProtectedString(QString *output, const QStringRef &str)
{
int n = str.length();
QString marked;
marked.reserve(n * 2 + 30);
output->reserve(output->size() + n * 2 + 30);
const QChar *data = str.constData();
for (int i = 0; i != n; ++i) {
switch (data[i].unicode()) {
case '&': marked += samp; break;
case '<': marked += slt; break;
case '>': marked += sgt; break;
case '"': marked += squot; break;
default : marked += data[i];
case '&': *output += samp; break;
case '<': *output += slt; break;
case '>': *output += sgt; break;
case '"': *output += squot; break;
default : *output += data[i];
}
}
return marked;
}
QString CodeMarker::typified(const QString &string)

View File

@ -163,8 +163,8 @@ public:
protected:
virtual QString sortName(const Node *node, const QString* name = 0);
QString protect(const QString &string);
QString protect(const QStringRef &string);
static QString protect(const QString &string);
static void appendProtectedString(QString *output, const QStringRef &str);
QString taggedNode(const Node* node);
QString taggedQmlNode(const Node* node);
QString linkTag(const Node *node, const QString& body);

View File

@ -929,8 +929,7 @@ QString CppCodeMarker::addMarkUp(const QString &in,
} else if (keywords.contains(ident)) {
tag = QStringLiteral("keyword");
} else if (braceDepth == 0 && parenDepth == 0) {
if (QString(code.unicode() + i - 1, code.length() - (i - 1))
.indexOf(findFunctionRegExp) == 0)
if (code.indexOf(findFunctionRegExp, i - 1) == i - 1)
tag = QStringLiteral("func");
target = true;
}
@ -1083,7 +1082,7 @@ QString CppCodeMarker::addMarkUp(const QString &in,
out += QStringLiteral(">");
}
out += protect(text);
appendProtectedString(&out, text);
if (!tag.isEmpty()) {
out += QStringLiteral("</@");
@ -1093,7 +1092,7 @@ QString CppCodeMarker::addMarkUp(const QString &in,
}
if (start < code.length()) {
out += protect(code.midRef(start));
appendProtectedString(&out, code.midRef(start));
}
return out;