Author: Kazu Hirata
Date: 2025-05-18T07:33:02-07:00
New Revision: 013c7ba78590badf20d769a2de13bddabcfb1c5d

URL: 
https://github.com/llvm/llvm-project/commit/013c7ba78590badf20d769a2de13bddabcfb1c5d
DIFF: 
https://github.com/llvm/llvm-project/commit/013c7ba78590badf20d769a2de13bddabcfb1c5d.diff

LOG: [CodeGen] Use DenseMap::try_emplace (NFC) (#140430)

We can simplify the code with DenseMap::try_emplace and structured
binding.  Note that DenseMap::try_emplace default-constructs the value
if omitted.

Added: 
    

Modified: 
    clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index aa9a55ae05927..514cc1d9015ee 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1818,9 +1818,7 @@ llvm::GlobalVariable 
*MicrosoftCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
   // VFTablesMap, thus a simple zero check is not sufficient.
 
   VFTableIdTy ID(RD, VPtrOffset);
-  VTablesMapTy::iterator I;
-  bool Inserted;
-  std::tie(I, Inserted) = VTablesMap.insert(std::make_pair(ID, nullptr));
+  auto [I, Inserted] = VTablesMap.try_emplace(ID);
   if (!Inserted)
     return I->second;
 
@@ -2036,10 +2034,7 @@ const VBTableGlobals &
 MicrosoftCXXABI::enumerateVBTables(const CXXRecordDecl *RD) {
   // At this layer, we can key the cache off of a single class, which is much
   // easier than caching each vbtable individually.
-  llvm::DenseMap<const CXXRecordDecl*, VBTableGlobals>::iterator Entry;
-  bool Added;
-  std::tie(Entry, Added) =
-      VBTablesMap.insert(std::make_pair(RD, VBTableGlobals()));
+  auto [Entry, Added] = VBTablesMap.try_emplace(RD);
   VBTableGlobals &VBGlobals = Entry->second;
   if (!Added)
     return VBGlobals;


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to