Skip to content

Commit 07ff786

Browse files
[TableGen] Avoid repeated hash lookups (NFC) (llvm#122586)
1 parent 17ef436 commit 07ff786

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

llvm/utils/TableGen/Common/CodeGenSchedule.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,9 @@ void CodeGenSchedModels::checkSTIPredicates() const {
258258
// There cannot be multiple declarations with the same name.
259259
for (const Record *R : Records.getAllDerivedDefinitions("STIPredicateDecl")) {
260260
StringRef Name = R->getValueAsString("Name");
261-
const auto It = Declarations.find(Name);
262-
if (It == Declarations.end()) {
263-
Declarations[Name] = R;
261+
const auto [It, Inserted] = Declarations.try_emplace(Name, R);
262+
if (Inserted)
264263
continue;
265-
}
266264

267265
PrintError(R->getLoc(), "STIPredicate " + Name + " multiply declared.");
268266
PrintFatalNote(It->second->getLoc(), "Previous declaration was here.");
@@ -417,9 +415,9 @@ void CodeGenSchedModels::collectSTIPredicates() {
417415
for (const Record *R : Records.getAllDerivedDefinitions("STIPredicate")) {
418416
const Record *Decl = R->getValueAsDef("Declaration");
419417

420-
const auto It = Decl2Index.find(Decl);
421-
if (It == Decl2Index.end()) {
422-
Decl2Index[Decl] = STIPredicates.size();
418+
const auto [It, Inserted] =
419+
Decl2Index.try_emplace(Decl, STIPredicates.size());
420+
if (Inserted) {
423421
STIPredicateFunction Predicate(Decl);
424422
Predicate.addDefinition(R);
425423
STIPredicates.emplace_back(std::move(Predicate));

0 commit comments

Comments
 (0)