From 67638d08b482150f2bace66b4836e278b73cc214 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 22 Jul 2015 14:19:07 +0200 Subject: Optimize CppCodeMarker::addMarkUp() This cuts away another 15% of the running time of qdoc -prepare. Change-Id: I81bc32fa191b73fad5d7bd27ff22ac845f83a9ce Reviewed-by: Martin Smith --- src/tools/qdoc/codemarker.cpp | 18 ++++++++++++++++++ src/tools/qdoc/codemarker.h | 1 + src/tools/qdoc/cppcodemarker.cpp | 31 +++++++++++++++++++------------ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/tools/qdoc/codemarker.cpp b/src/tools/qdoc/codemarker.cpp index 56fd3505be..e00ebef2db 100644 --- a/src/tools/qdoc/codemarker.cpp +++ b/src/tools/qdoc/codemarker.cpp @@ -194,6 +194,24 @@ QString CodeMarker::protect(const QString& str) return marked; } +QString CodeMarker::protect(const QStringRef& str) +{ + int n = str.length(); + QString marked; + marked.reserve(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]; + } + } + return marked; +} + QString CodeMarker::typified(const QString &string) { QString result; diff --git a/src/tools/qdoc/codemarker.h b/src/tools/qdoc/codemarker.h index c5226fff04..e407e0ac3f 100644 --- a/src/tools/qdoc/codemarker.h +++ b/src/tools/qdoc/codemarker.h @@ -164,6 +164,7 @@ public: protected: virtual QString sortName(const Node *node, const QString* name = 0); QString protect(const QString &string); + QString protect(const QStringRef &string); QString taggedNode(const Node* node); QString taggedQmlNode(const Node* node); QString linkTag(const Node *node, const QString& body); diff --git a/src/tools/qdoc/cppcodemarker.cpp b/src/tools/qdoc/cppcodemarker.cpp index 9aec902860..6060339762 100644 --- a/src/tools/qdoc/cppcodemarker.cpp +++ b/src/tools/qdoc/cppcodemarker.cpp @@ -893,8 +893,8 @@ QString CppCodeMarker::addMarkUp(const QString &in, ch = (i < (int)code.length()) ? code[i++].cell() : EOF QString code = in; - QStringList out; - QString text; + QString out; + QStringRef text; int braceDepth = 0; int parenDepth = 0; int i = 0; @@ -1069,27 +1069,34 @@ QString CppCodeMarker::addMarkUp(const QString &in, } } - text = code.mid(start, finish - start); + text = code.midRef(start, finish - start); start = finish; if (!tag.isEmpty()) { - out << QStringLiteral("<@") << tag; - if (target) - out << QStringLiteral(" target=\"") << text << QStringLiteral("()\""); - out << QStringLiteral(">"); + out += QStringLiteral("<@"); + out += tag; + if (target) { + out += QStringLiteral(" target=\""); + out += text; + out += QStringLiteral("()\""); + } + out += QStringLiteral(">"); } - out << protect(text); + out += protect(text); - if (!tag.isEmpty()) - out << QStringLiteral(""); + if (!tag.isEmpty()) { + out += QStringLiteral(""); + } } if (start < code.length()) { - out << protect(code.mid(start)); + out += protect(code.midRef(start)); } - return out.join(QString()); + return out; } /*! -- cgit v1.2.3