Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2024

@llvm/pr-subscribers-clang-tools-extra

Author: Kazu Hirata (kazutakahirata)

Changes

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.


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

2 Files Affected:

  • (modified) clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.cpp (+1-1)
  • (modified) clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h (+2-1)
diff --git a/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.cpp b/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.cpp
index 93b534d26f2ce3..6d272af7436923 100644
--- a/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.cpp
+++ b/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.cpp
@@ -21,7 +21,7 @@ InMemorySymbolIndex::InMemorySymbolIndex(
 
 std::vector<SymbolAndSignals>
 InMemorySymbolIndex::search(llvm::StringRef Identifier) {
-  auto I = LookupTable.find(std::string(Identifier));
+  auto I = LookupTable.find(Identifier);
   if (I != LookupTable.end())
     return I->second;
   return {};
diff --git a/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h b/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h
index bea8be91a43c75..c91a7a3a0a10e4 100644
--- a/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h
+++ b/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h
@@ -27,7 +27,8 @@ class InMemorySymbolIndex : public SymbolIndex {
   search(llvm::StringRef Identifier) override;
 
 private:
-  std::map<std::string, std::vector<find_all_symbols::SymbolAndSignals>>
+  std::map<std::string, std::vector<find_all_symbols::SymbolAndSignals>,
+           std::less<>>
       LookupTable;
 };
 

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

LGTM

@kazutakahirata kazutakahirata merged commit b7ee03f into llvm:main Nov 6, 2024
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_heterogenous_clang_include_fixer branch November 6, 2024 16:35
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.

3 participants