From 7e572841f7fe264c09d941ce72d81ac06140fc80 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 7 Aug 2023 11:53:52 +0200 Subject: [PATCH] Valgrind: Make tool name hash static Change-Id: I326c45e1be293dc5066271839b26b7f22d53eabb Reviewed-by: Qt CI Bot Reviewed-by: hjk Reviewed-by: --- src/plugins/valgrind/xmlprotocol/parser.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/plugins/valgrind/xmlprotocol/parser.cpp b/src/plugins/valgrind/xmlprotocol/parser.cpp index 96813fd11b4..b3e6a41c0b9 100644 --- a/src/plugins/valgrind/xmlprotocol/parser.cpp +++ b/src/plugins/valgrind/xmlprotocol/parser.cpp @@ -66,6 +66,17 @@ enum class Tool { Helgrind }; +const QHash &toolByName() +{ + static const QHash theHash { + {"memcheck", Tool::Memcheck}, + {"ptrcheck", Tool::Ptrcheck}, + {"exp-ptrcheck", Tool::Ptrcheck}, + {"helgrind", Tool::Helgrind} + }; + return theHash; +} + class Parser::Private { public: @@ -97,7 +108,6 @@ private: Tool tool = Tool::Unknown; QXmlStreamReader reader; - QHash toolsByName; private: Parser *const q; @@ -106,10 +116,6 @@ private: Parser::Private::Private(Parser *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) @@ -223,8 +229,8 @@ void Parser::Private::checkProtocolVersion(const QString &versionStr) void Parser::Private::checkTool(const QString &reportedStr) { - const auto reported = toolsByName.constFind(reportedStr); - if (reported == toolsByName.constEnd()) + const auto reported = toolByName().constFind(reportedStr); + if (reported == toolByName().constEnd()) throw ParserException(Tr::tr("Valgrind tool \"%1\" not supported").arg(reportedStr)); tool = reported.value();