Skip to content

Commit 3297858

Browse files
[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.
1 parent a6fdfef commit 3297858

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/tools/llvm-readobj/ObjDumper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static std::vector<object::SectionRef>
106106
getSectionRefsByNameOrIndex(const object::ObjectFile &Obj,
107107
ArrayRef<std::string> Sections) {
108108
std::vector<object::SectionRef> Ret;
109-
std::map<std::string, bool> SecNames;
109+
std::map<std::string, bool, std::less<>> SecNames;
110110
std::map<unsigned, bool> SecIndices;
111111
unsigned SecIndex;
112112
for (StringRef Section : Sections) {
@@ -119,7 +119,7 @@ getSectionRefsByNameOrIndex(const object::ObjectFile &Obj,
119119
SecIndex = Obj.isELF() ? 0 : 1;
120120
for (object::SectionRef SecRef : Obj.sections()) {
121121
StringRef SecName = unwrapOrError(Obj.getFileName(), SecRef.getName());
122-
auto NameIt = SecNames.find(std::string(SecName));
122+
auto NameIt = SecNames.find(SecName);
123123
if (NameIt != SecNames.end())
124124
NameIt->second = true;
125125
auto IndexIt = SecIndices.find(SecIndex);

0 commit comments

Comments
 (0)