From fec04f286ef5914f81a5bc188eb2f60cfdbacce8 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 13 Feb 2025 09:11:43 -0800 Subject: [FileCheck] Avoid repeated hash lookups (NFC) (#127026) --- llvm/lib/FileCheck/FileCheck.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'llvm/lib/FileCheck/FileCheck.cpp') diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp index 5706afc357fb..931a4d3c36f1 100644 --- a/llvm/lib/FileCheck/FileCheck.cpp +++ b/llvm/lib/FileCheck/FileCheck.cpp @@ -386,15 +386,12 @@ Expected> Pattern::parseNumericVariableUse( // that happens, we create a dummy variable so that parsing can continue. All // uses of undefined variables, whether string or numeric, are then diagnosed // in printNoMatch() after failing to match. - auto VarTableIter = Context->GlobalNumericVariableTable.find(Name); - NumericVariable *NumericVariable; - if (VarTableIter != Context->GlobalNumericVariableTable.end()) - NumericVariable = VarTableIter->second; - else { - NumericVariable = Context->makeNumericVariable( + auto [VarTableIter, Inserted] = + Context->GlobalNumericVariableTable.try_emplace(Name); + if (Inserted) + VarTableIter->second = Context->makeNumericVariable( Name, ExpressionFormat(ExpressionFormat::Kind::Unsigned)); - Context->GlobalNumericVariableTable[Name] = NumericVariable; - } + NumericVariable *NumericVariable = VarTableIter->second; std::optional DefLineNumber = NumericVariable->getDefLineNumber(); if (DefLineNumber && LineNumber && *DefLineNumber == *LineNumber) -- cgit v1.2.3