From 3e52b31a5c738d11f160009bfa45db8e203ff652 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 3 Mar 2025 08:59:17 -0800 Subject: [PATCH] [llvm-readobj] Avoid repeated hash lookups (NFC) --- llvm/tools/llvm-readobj/COFFDumper.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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; }