Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lld] Avoid repeated map lookups (NFC) #132327

Merged

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 21, 2025

@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-lld-coff

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/132327.diff

1 Files Affected:

  • (modified) lld/COFF/Writer.cpp (+1-2)
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index f488721106e15..6ed1f884a9636 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1278,8 +1278,7 @@ void Writer::createImportTables() {
       continue;
 
     std::string dll = StringRef(file->dllName).lower();
-    if (ctx.config.dllOrder.count(dll) == 0)
-      ctx.config.dllOrder[dll] = ctx.config.dllOrder.size();
+    ctx.config.dllOrder.try_emplace(dll, ctx.config.dllOrder.size());
 
     if (file->impSym && !isa<DefinedImportData>(file->impSym))
       Fatal(ctx) << file->symtab.printSymbol(file->impSym) << " was replaced";

@llvmbot
Copy link
Member

llvmbot commented Mar 21, 2025

@llvm/pr-subscribers-lld

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/132327.diff

1 Files Affected:

  • (modified) lld/COFF/Writer.cpp (+1-2)
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index f488721106e15..6ed1f884a9636 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1278,8 +1278,7 @@ void Writer::createImportTables() {
       continue;
 
     std::string dll = StringRef(file->dllName).lower();
-    if (ctx.config.dllOrder.count(dll) == 0)
-      ctx.config.dllOrder[dll] = ctx.config.dllOrder.size();
+    ctx.config.dllOrder.try_emplace(dll, ctx.config.dllOrder.size());
 
     if (file->impSym && !isa<DefinedImportData>(file->impSym))
       Fatal(ctx) << file->symtab.printSymbol(file->impSym) << " was replaced";

Copy link
Contributor

@Zhenhang1213 Zhenhang1213 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Zhenhang1213 Zhenhang1213 merged commit 690b8b4 into llvm:main Mar 21, 2025
15 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_lld branch March 21, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants