[clang-tools-extra] b7ee03f - [clang-include-fixer] Use heterogenous lookups with std::map (NFC) (#115113)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 08:35:28 PST 2024


Author: Kazu Hirata
Date: 2024-11-06T08:35:24-08:00
New Revision: b7ee03ffb8696c4d81a5a97c61cb2149c17e6573

URL: https://github.com/llvm/llvm-project/commit/b7ee03ffb8696c4d81a5a97c61cb2149c17e6573
DIFF: https://github.com/llvm/llvm-project/commit/b7ee03ffb8696c4d81a5a97c61cb2149c17e6573.diff

LOG: [clang-include-fixer] Use heterogenous lookups with std::map (NFC) (#115113)

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

Added: 
    

Modified: 
    clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.cpp
    clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h

Removed: 
    


################################################################################
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;
 };
 


        


More information about the cfe-commits mailing list