[llvm] 1714fac - [TableGen] Avoid repeated map lookups (NFC) (#123699)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 21 00:23:26 PST 2025


Author: Kazu Hirata
Date: 2025-01-21T16:23:23+08:00
New Revision: 1714facf4f7d7f4ef5a1846aded769fec8e684ac

URL: https://github.com/llvm/llvm-project/commit/1714facf4f7d7f4ef5a1846aded769fec8e684ac
DIFF: https://github.com/llvm/llvm-project/commit/1714facf4f7d7f4ef5a1846aded769fec8e684ac.diff

LOG: [TableGen] Avoid repeated map lookups (NFC) (#123699)

Added: 
    

Modified: 
    llvm/utils/TableGen/Basic/VTEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/Basic/VTEmitter.cpp b/llvm/utils/TableGen/Basic/VTEmitter.cpp
index d02932dd5e7fca..07840d397bb156 100644
--- a/llvm/utils/TableGen/Basic/VTEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/VTEmitter.cpp
@@ -109,12 +109,13 @@ void VTEmitter::run(raw_ostream &OS) {
   auto UpdateVTRange = [&VTRanges](const char *Key, StringRef Name,
                                    bool Valid) {
     if (Valid) {
-      if (!VTRanges.count(Key))
-        VTRanges[Key].First = Name;
-      assert(!VTRanges[Key].Closed && "Gap detected!");
-      VTRanges[Key].Last = Name;
-    } else if (VTRanges.count(Key)) {
-      VTRanges[Key].Closed = true;
+      auto [It, Inserted] = VTRanges.try_emplace(Key);
+      if (Inserted)
+        It->second.First = Name;
+      assert(!It->second.Closed && "Gap detected!");
+      It->second.Last = Name;
+    } else if (auto It = VTRanges.find(Key); It != VTRanges.end()) {
+      It->second.Closed = true;
     }
   };
 


        


More information about the llvm-commits mailing list