[llvm] [FileCheck] Avoid repeated hash lookups (NFC) (PR #127026)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 13 00:04:57 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/127026
None
>From 8fb291ef21fa33d4e708f9defb43d09006004feb Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 12 Feb 2025 09:08:02 -0800
Subject: [PATCH] [FileCheck] Avoid repeated hash lookups (NFC)
---
llvm/lib/FileCheck/FileCheck.cpp | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
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)
More information about the llvm-commits
mailing list