Skip to content

Commit 93f7fce

Browse files
[ByteCode] Avoid repeated hash lookups (NFC) (#111273)
1 parent 9e6578c commit 93f7fce

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,13 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
284284
if (!RD->isCompleteDefinition())
285285
return nullptr;
286286

287-
// Deduplicate records.
288-
if (auto It = Records.find(RD); It != Records.end())
287+
// Return an existing record if available. Otherwise, we insert nullptr now
288+
// and replace that later, so recursive calls to this function with the same
289+
// RecordDecl don't run into infinite recursion.
290+
auto [It, Inserted] = Records.try_emplace(RD);
291+
if (!Inserted)
289292
return It->second;
290293

291-
// We insert nullptr now and replace that later, so recursive calls
292-
// to this function with the same RecordDecl don't run into
293-
// infinite recursion.
294-
Records.insert({RD, nullptr});
295-
296294
// Number of bytes required by fields and base classes.
297295
unsigned BaseSize = 0;
298296
// Number of bytes required by virtual base.

0 commit comments

Comments
 (0)