Skip to content

Commit ac583df

Browse files
[include-cleaner] Use heterogeneous lookups (NFC) (#139685)
Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string.
1 parent 29a4561 commit ac583df

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,11 @@ std::function<bool(llvm::StringRef)> headerFilter() {
312312

313313
// Maps absolute path of each files of each compilation commands to the
314314
// absolute path of the input file.
315-
llvm::Expected<std::map<std::string, std::string>>
315+
llvm::Expected<std::map<std::string, std::string, std::less<>>>
316316
mapInputsToAbsPaths(clang::tooling::CompilationDatabase &CDB,
317317
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
318318
const std::vector<std::string> &Inputs) {
319-
std::map<std::string, std::string> CDBToAbsPaths;
319+
std::map<std::string, std::string, std::less<>> CDBToAbsPaths;
320320
// Factory.editedFiles()` will contain the final code, along with the
321321
// path given in the compilation database. That path can be
322322
// absolute or relative, and if it is relative, it is relative to the
@@ -395,8 +395,7 @@ int main(int argc, const char **argv) {
395395
if (Edit) {
396396
for (const auto &NameAndContent : Factory.editedFiles()) {
397397
llvm::StringRef FileName = NameAndContent.first();
398-
if (auto It = CDBToAbsPaths->find(FileName.str());
399-
It != CDBToAbsPaths->end())
398+
if (auto It = CDBToAbsPaths->find(FileName); It != CDBToAbsPaths->end())
400399
FileName = It->second;
401400

402401
const std::string &FinalCode = NameAndContent.second;

0 commit comments

Comments
 (0)