Skip to content

Commit

Permalink
Optimize CppCodeMarker::addMarkUp further
Browse files Browse the repository at this point in the history
This avoids a couple of more string/memory
allocations, giving another 5% speed gain
for qdoc --prepare.

Change-Id: I455f615bb4388d883dca5a8cd31bf50629db23e0
Reviewed-by: Martin Smith <[email protected]>
  • Loading branch information
laknoll committed Jul 24, 2015
1 parent 5fd9fe0 commit dbf4c62
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
16 changes: 7 additions & 9 deletions src/tools/qdoc/codemarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/tools/qdoc/codemarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ class CodeMarker

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);
Expand Down
7 changes: 3 additions & 4 deletions src/tools/qdoc/cppcodemarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -1083,7 +1082,7 @@ QString CppCodeMarker::addMarkUp(const QString &in,
out += QStringLiteral(">");
}

out += protect(text);
appendProtectedString(&out, text);

if (!tag.isEmpty()) {
out += QStringLiteral("</@");
Expand All @@ -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;
Expand Down

0 comments on commit dbf4c62

Please sign in to comment.