From b7ee03ffb8696c4d81a5a97c61cb2149c17e6573 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 6 Nov 2024 08:35:24 -0800 Subject: [PATCH] [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. --- 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 93b534d26f2c..6d272af74369 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 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 bea8be91a43c..c91a7a3a0a10 100644 --- a/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h +++ b/clang-tools-extra/clang-include-fixer/InMemorySymbolIndex.h @@ -27,7 +27,8 @@ public: search(llvm::StringRef Identifier) override; private: - std::map> + std::map, + std::less<>> LookupTable; };