From 8bf1529894d42126757614a42b99e0e9e85532f0 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 11 Sep 2020 18:38:57 +0300 Subject: [PATCH] optimize QXmlUtils::isEncName() Signed-off-by: Ivailo Monev --- src/xml/kernel/qxmlutils.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/xml/kernel/qxmlutils.cpp b/src/xml/kernel/qxmlutils.cpp index 2764cb5a8..d0635a146 100644 --- a/src/xml/kernel/qxmlutils.cpp +++ b/src/xml/kernel/qxmlutils.cpp @@ -31,7 +31,6 @@ ** ****************************************************************************/ -#include "qregexp.h" #include "qstring.h" #include "qxmlutils_p.h" @@ -194,14 +193,24 @@ static inline bool isCombiningChar(const QChar c) */ bool QXmlUtils::isEncName(const QString &encName) { - /* Right, we here have a dependency on QRegExp. Writing a manual parser to - * replace that regexp is probably a 70 lines so I prioritize this to when - * the dependency is considered alarming, or when the rest of the bugs - * are fixed. */ - const QRegExp encNameRegExp(QLatin1String("[A-Za-z][A-Za-z0-9._\\-]*")); - Q_ASSERT(encNameRegExp.isValid()); + if (encName.size() < 2) + return false; - return encNameRegExp.exactMatch(encName); + const ushort first = encName.at(0).unicode(); + if ((first >= 'a' && first <= 'z') + || (first >= 'A' && first <= 'Z')) + { + const ushort second = encName.at(1).unicode(); + if ((second >= 'a' && second <= 'z') + || (second >= 'A' && second <= 'Z') + || (second >= '0' && second <= '9') + || second == '.' || second == '_' || second == '-') + { + return true; + } + } + + return false; } /*!