diff options
author | Kazu Hirata <kazu@google.com> | 2025-02-13 09:11:43 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-13 09:11:43 -0800 |
commit | fec04f286ef5914f81a5bc188eb2f60cfdbacce8 (patch) | |
tree | c00cfb184ec9ab0ef40daf8e5dca5fa62c92e175 /llvm/lib/FileCheck/FileCheck.cpp | |
parent | e7bf6a4e042fba2b1492be8fc5f430df3e9a43d2 (diff) | |
download | llvm-fec04f286ef5914f81a5bc188eb2f60cfdbacce8.zip llvm-fec04f286ef5914f81a5bc188eb2f60cfdbacce8.tar.gz llvm-fec04f286ef5914f81a5bc188eb2f60cfdbacce8.tar.bz2 |
[FileCheck] Avoid repeated hash lookups (NFC) (#127026)
Diffstat (limited to 'llvm/lib/FileCheck/FileCheck.cpp')
-rw-r--r-- | llvm/lib/FileCheck/FileCheck.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp index 5706afc..931a4d3 100644 --- a/llvm/lib/FileCheck/FileCheck.cpp +++ b/llvm/lib/FileCheck/FileCheck.cpp @@ -386,15 +386,12 @@ Expected<std::unique_ptr<NumericVariableUse>> 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<size_t> DefLineNumber = NumericVariable->getDefLineNumber(); if (DefLineNumber && LineNumber && *DefLineNumber == *LineNumber) |