https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/115113
Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string. >From d83d2c1478982e3c09ef7c7e80880e3f874c69eb Mon Sep 17 00:00:00 2001 From: Kazu Hirata <k...@google.com> Date: Tue, 5 Nov 2024 10:11:22 -0800 Subject: [PATCH] [clang-include-fixer] Use heterogenous lookups with std::map (NFC) Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string. --- clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.cpp | 2 +- clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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; }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits