[clang] 93f7fce - [ByteCode] Avoid repeated hash lookups (NFC) (#111273)

via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 6 09:22:16 PDT 2024


Author: Kazu Hirata
Date: 2024-10-06T09:22:13-07:00
New Revision: 93f7fce397155f40de46d867c345e335b30b8d5c

URL: https://github.com/llvm/llvm-project/commit/93f7fce397155f40de46d867c345e335b30b8d5c
DIFF: https://github.com/llvm/llvm-project/commit/93f7fce397155f40de46d867c345e335b30b8d5c.diff

LOG: [ByteCode] Avoid repeated hash lookups (NFC) (#111273)

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Program.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp
index 969f523db51dfe..23245a66b578ae 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -284,15 +284,13 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
   if (!RD->isCompleteDefinition())
     return nullptr;
 
-  // Deduplicate records.
-  if (auto It = Records.find(RD); It != Records.end())
+  // Return an existing record if available.  Otherwise, we insert nullptr now
+  // and replace that later, so recursive calls to this function with the same
+  // RecordDecl don't run into infinite recursion.
+  auto [It, Inserted] = Records.try_emplace(RD);
+  if (!Inserted)
     return It->second;
 
-  // We insert nullptr now and replace that later, so recursive calls
-  // to this function with the same RecordDecl don't run into
-  // infinite recursion.
-  Records.insert({RD, nullptr});
-
   // Number of bytes required by fields and base classes.
   unsigned BaseSize = 0;
   // Number of bytes required by virtual base.


        


More information about the cfe-commits mailing list