[llvm] [FileCheck] Avoid repeated hash lookups (NFC) (PR #127026)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 13 00:05:34 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-testing-tools
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/127026.diff
1 Files Affected:
- (modified) llvm/lib/FileCheck/FileCheck.cpp (+5-8)
``````````diff
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 5706afc357fbd..931a4d3c36f16 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)
``````````
</details>
https://github.com/llvm/llvm-project/pull/127026
More information about the llvm-commits
mailing list