Author: Kazu Hirata Date: 2025-05-13T07:13:25-07:00 New Revision: ac583df03b3c1b2cc3ef7ececbeca697f3449bec
URL: https://github.com/llvm/llvm-project/commit/ac583df03b3c1b2cc3ef7ececbeca697f3449bec DIFF: https://github.com/llvm/llvm-project/commit/ac583df03b3c1b2cc3ef7ececbeca697f3449bec.diff LOG: [include-cleaner] Use heterogeneous lookups (NFC) (#139685) Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string. Added: Modified: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp index 9431211b03e71..372ab5fa2706e 100644 --- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp +++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp @@ -312,11 +312,11 @@ std::function<bool(llvm::StringRef)> headerFilter() { // Maps absolute path of each files of each compilation commands to the // absolute path of the input file. -llvm::Expected<std::map<std::string, std::string>> +llvm::Expected<std::map<std::string, std::string, std::less<>>> mapInputsToAbsPaths(clang::tooling::CompilationDatabase &CDB, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, const std::vector<std::string> &Inputs) { - std::map<std::string, std::string> CDBToAbsPaths; + std::map<std::string, std::string, std::less<>> CDBToAbsPaths; // Factory.editedFiles()` will contain the final code, along with the // path given in the compilation database. That path can be // absolute or relative, and if it is relative, it is relative to the @@ -395,8 +395,7 @@ int main(int argc, const char **argv) { if (Edit) { for (const auto &NameAndContent : Factory.editedFiles()) { llvm::StringRef FileName = NameAndContent.first(); - if (auto It = CDBToAbsPaths->find(FileName.str()); - It != CDBToAbsPaths->end()) + if (auto It = CDBToAbsPaths->find(FileName); It != CDBToAbsPaths->end()) FileName = It->second; const std::string &FinalCode = NameAndContent.second; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits