[llvm] 3297858 - [llvm-readobj] Use heterogenous lookups with std::map (NFC) (#114929)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 09:38:15 PST 2024


Author: Kazu Hirata
Date: 2024-11-05T09:38:11-08:00
New Revision: 3297858c19f3914513041d2c8407bc26c889793a

URL: https://github.com/llvm/llvm-project/commit/3297858c19f3914513041d2c8407bc26c889793a
DIFF: https://github.com/llvm/llvm-project/commit/3297858c19f3914513041d2c8407bc26c889793a.diff

LOG: [llvm-readobj] Use heterogenous lookups with std::map (NFC) (#114929)

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp
index d02d1e543d31dc..d3c613ee823bae 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -106,7 +106,7 @@ static std::vector<object::SectionRef>
 getSectionRefsByNameOrIndex(const object::ObjectFile &Obj,
                             ArrayRef<std::string> Sections) {
   std::vector<object::SectionRef> Ret;
-  std::map<std::string, bool> SecNames;
+  std::map<std::string, bool, std::less<>> SecNames;
   std::map<unsigned, bool> SecIndices;
   unsigned SecIndex;
   for (StringRef Section : Sections) {
@@ -119,7 +119,7 @@ getSectionRefsByNameOrIndex(const object::ObjectFile &Obj,
   SecIndex = Obj.isELF() ? 0 : 1;
   for (object::SectionRef SecRef : Obj.sections()) {
     StringRef SecName = unwrapOrError(Obj.getFileName(), SecRef.getName());
-    auto NameIt = SecNames.find(std::string(SecName));
+    auto NameIt = SecNames.find(SecName);
     if (NameIt != SecNames.end())
       NameIt->second = true;
     auto IndexIt = SecIndices.find(SecIndex);


        


More information about the llvm-commits mailing list