From 3297858c19f3914513041d2c8407bc26c889793a Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 5 Nov 2024 09:38:11 -0800 Subject: [PATCH] [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. --- llvm/tools/llvm-readobj/ObjDumper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp index d02d1e543d31..d3c613ee823b 100644 --- a/llvm/tools/llvm-readobj/ObjDumper.cpp +++ b/llvm/tools/llvm-readobj/ObjDumper.cpp @@ -106,7 +106,7 @@ static std::vector getSectionRefsByNameOrIndex(const object::ObjectFile &Obj, ArrayRef Sections) { std::vector Ret; - std::map SecNames; + std::map> SecNames; std::map 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);