Skip to content

[clang-installapi] Avoid repeated hash lookups (NFC) #126677

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

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@kazutakahirata kazutakahirata requested a review from nikic February 11, 2025 06:08
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Feb 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2025

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) clang/tools/clang-installapi/Options.cpp (+13-7)
diff --git a/clang/tools/clang-installapi/Options.cpp b/clang/tools/clang-installapi/Options.cpp
index 8a2c3463189fa9c..0dddcfce58ca695 100644
--- a/clang/tools/clang-installapi/Options.cpp
+++ b/clang/tools/clang-installapi/Options.cpp
@@ -263,11 +263,12 @@ bool Options::processInstallAPIXOptions(InputArgList &Args) {
     }
     const StringRef ASpelling = NextA->getSpelling();
     const auto &AValues = NextA->getValues();
+    auto &UniqueArgs = FEOpts.UniqueArgs[Label];
     if (AValues.empty())
-      FEOpts.UniqueArgs[Label].emplace_back(ASpelling.str());
+      UniqueArgs.emplace_back(ASpelling.str());
     else
       for (const StringRef Val : AValues)
-        FEOpts.UniqueArgs[Label].emplace_back((ASpelling + Val).str());
+        UniqueArgs.emplace_back((ASpelling + Val).str());
 
     A->claim();
     NextA->claim();
@@ -608,32 +609,37 @@ Options::processAndFilterOutInstallAPIOptions(ArrayRef<const char *> Args) {
       ParsedArgs.hasArg(OPT_not_for_dyld_shared_cache);
 
   for (const Arg *A : ParsedArgs.filtered(OPT_allowable_client)) {
+    auto It = ArgToArchMap.find(A);
     LinkerOpts.AllowableClients[A->getValue()] =
-        ArgToArchMap.count(A) ? ArgToArchMap[A] : ArchitectureSet();
+        It != ArgToArchMap.end() ? It->second : ArchitectureSet();
     A->claim();
   }
 
   for (const Arg *A : ParsedArgs.filtered(OPT_reexport_l)) {
+    auto It = ArgToArchMap.find(A);
     LinkerOpts.ReexportedLibraries[A->getValue()] =
-        ArgToArchMap.count(A) ? ArgToArchMap[A] : ArchitectureSet();
+        It != ArgToArchMap.end() ? It->second : ArchitectureSet();
     A->claim();
   }
 
   for (const Arg *A : ParsedArgs.filtered(OPT_reexport_library)) {
+    auto It = ArgToArchMap.find(A);
     LinkerOpts.ReexportedLibraryPaths[A->getValue()] =
-        ArgToArchMap.count(A) ? ArgToArchMap[A] : ArchitectureSet();
+        It != ArgToArchMap.end() ? It->second : ArchitectureSet();
     A->claim();
   }
 
   for (const Arg *A : ParsedArgs.filtered(OPT_reexport_framework)) {
+    auto It = ArgToArchMap.find(A);
     LinkerOpts.ReexportedFrameworks[A->getValue()] =
-        ArgToArchMap.count(A) ? ArgToArchMap[A] : ArchitectureSet();
+        It != ArgToArchMap.end() ? It->second : ArchitectureSet();
     A->claim();
   }
 
   for (const Arg *A : ParsedArgs.filtered(OPT_rpath)) {
+    auto It = ArgToArchMap.find(A);
     LinkerOpts.RPaths[A->getValue()] =
-        ArgToArchMap.count(A) ? ArgToArchMap[A] : ArchitectureSet();
+        It != ArgToArchMap.end() ? It->second : ArchitectureSet();
     A->claim();
   }
 

@kazutakahirata kazutakahirata merged commit 43c82a8 into llvm:main Feb 11, 2025
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_clang_installapi branch February 11, 2025 17:07
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants