Valgrind: Make tool name hash static

Change-Id: I326c45e1be293dc5066271839b26b7f22d53eabb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2023-08-07 11:53:52 +02:00
parent fbb06f1a02
commit 7e572841f7

View File

@@ -66,6 +66,17 @@ enum class Tool {
Helgrind Helgrind
}; };
const QHash<QString, Tool> &toolByName()
{
static const QHash<QString, Tool> theHash {
{"memcheck", Tool::Memcheck},
{"ptrcheck", Tool::Ptrcheck},
{"exp-ptrcheck", Tool::Ptrcheck},
{"helgrind", Tool::Helgrind}
};
return theHash;
}
class Parser::Private class Parser::Private
{ {
public: public:
@@ -97,7 +108,6 @@ private:
Tool tool = Tool::Unknown; Tool tool = Tool::Unknown;
QXmlStreamReader reader; QXmlStreamReader reader;
QHash<QString, Tool> toolsByName;
private: private:
Parser *const q; Parser *const q;
@@ -106,10 +116,6 @@ private:
Parser::Private::Private(Parser *qq) Parser::Private::Private(Parser *qq)
: q(qq) : q(qq)
{ {
toolsByName.insert("memcheck", Tool::Memcheck);
toolsByName.insert("ptrcheck", Tool::Ptrcheck);
toolsByName.insert("exp-ptrcheck", Tool::Ptrcheck);
toolsByName.insert("helgrind", Tool::Helgrind);
} }
static quint64 parseHex(const QString &str, const QString &context) static quint64 parseHex(const QString &str, const QString &context)
@@ -223,8 +229,8 @@ void Parser::Private::checkProtocolVersion(const QString &versionStr)
void Parser::Private::checkTool(const QString &reportedStr) void Parser::Private::checkTool(const QString &reportedStr)
{ {
const auto reported = toolsByName.constFind(reportedStr); const auto reported = toolByName().constFind(reportedStr);
if (reported == toolsByName.constEnd()) if (reported == toolByName().constEnd())
throw ParserException(Tr::tr("Valgrind tool \"%1\" not supported").arg(reportedStr)); throw ParserException(Tr::tr("Valgrind tool \"%1\" not supported").arg(reportedStr));
tool = reported.value(); tool = reported.value();