[llvm] [Object] Avoid repeated map lookups (NFC) (PR #110201)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 27 11:14:17 PDT 2024


https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/110201

>From 56da9b5f90878e93ccd12754f0ef1358fd072cd9 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 26 Sep 2024 08:15:54 -0700
Subject: [PATCH] [Object] Avoid repeated map lookups (NFC)

---
 llvm/lib/Object/ArchiveWriter.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index 114045561366d7..c61ba868efe60e 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -754,9 +754,8 @@ static Expected<std::vector<unsigned>> getSymbols(SymbolicFile *Obj,
       raw_string_ostream NameStream(Name);
       if (Error E = S.printName(NameStream))
         return std::move(E);
-      if (Map->find(Name) != Map->end())
+      if (!Map->try_emplace(Name, Index).second)
         continue; // ignore duplicated symbol
-      (*Map)[Name] = Index;
       if (Map == &SymMap->Map) {
         Ret.push_back(SymNames.tell());
         SymNames << Name << '\0';



More information about the llvm-commits mailing list