Skip to content

Commit fec04f2

Browse files
[FileCheck] Avoid repeated hash lookups (NFC) (llvm#127026)
1 parent e7bf6a4 commit fec04f2

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,12 @@ Expected<std::unique_ptr<NumericVariableUse>> Pattern::parseNumericVariableUse(
386386
// that happens, we create a dummy variable so that parsing can continue. All
387387
// uses of undefined variables, whether string or numeric, are then diagnosed
388388
// in printNoMatch() after failing to match.
389-
auto VarTableIter = Context->GlobalNumericVariableTable.find(Name);
390-
NumericVariable *NumericVariable;
391-
if (VarTableIter != Context->GlobalNumericVariableTable.end())
392-
NumericVariable = VarTableIter->second;
393-
else {
394-
NumericVariable = Context->makeNumericVariable(
389+
auto [VarTableIter, Inserted] =
390+
Context->GlobalNumericVariableTable.try_emplace(Name);
391+
if (Inserted)
392+
VarTableIter->second = Context->makeNumericVariable(
395393
Name, ExpressionFormat(ExpressionFormat::Kind::Unsigned));
396-
Context->GlobalNumericVariableTable[Name] = NumericVariable;
397-
}
394+
NumericVariable *NumericVariable = VarTableIter->second;
398395

399396
std::optional<size_t> DefLineNumber = NumericVariable->getDefLineNumber();
400397
if (DefLineNumber && LineNumber && *DefLineNumber == *LineNumber)

0 commit comments

Comments
 (0)