[llvm] 65330e2 - [llvm-readobj] Avoid repeated hash lookups (NFC) (#129657)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 4 01:50:53 PST 2025


Author: Kazu Hirata
Date: 2025-03-04T01:50:50-08:00
New Revision: 65330e20b189c38ddbb38eb63b15f93262385e73

URL: https://github.com/llvm/llvm-project/commit/65330e20b189c38ddbb38eb63b15f93262385e73
DIFF: https://github.com/llvm/llvm-project/commit/65330e20b189c38ddbb38eb63b15f93262385e73.diff

LOG: [llvm-readobj] Avoid repeated hash lookups (NFC) (#129657)

Added: 
    

Modified: 
    llvm/tools/llvm-readobj/COFFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 1666f7692ad5f..5d1d2a34d6442 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -645,10 +645,11 @@ void COFFDumper::cacheRelocations() {
   for (const SectionRef &S : Obj->sections()) {
     const coff_section *Section = Obj->getCOFFSection(S);
 
-    append_range(RelocMap[Section], S.relocations());
+    auto &RM = RelocMap[Section];
+    append_range(RM, S.relocations());
 
     // Sort relocations by address.
-    llvm::sort(RelocMap[Section], [](RelocationRef L, RelocationRef R) {
+    llvm::sort(RM, [](RelocationRef L, RelocationRef R) {
       return L.getOffset() < R.getOffset();
     });
   }
@@ -1270,14 +1271,15 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
         reportError(errorCodeToError(EC), Obj->getFileName());
 
       W.printString("LinkageName", LinkageName);
-      if (FunctionLineTables.count(LinkageName) != 0) {
+      auto [It, Inserted] =
+          FunctionLineTables.try_emplace(LinkageName, Contents);
+      if (!Inserted) {
         // Saw debug info for this function already?
         reportError(errorCodeToError(object_error::parse_failed),
                     Obj->getFileName());
         return;
       }
 
-      FunctionLineTables[LinkageName] = Contents;
       FunctionNames.push_back(LinkageName);
       break;
     }


        


More information about the llvm-commits mailing list