[clang] [InstallAPI] Call DenseMap::find without constructing std::string (NFC) (PR #115260)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 20:21:39 PST 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/115260

KnownIncludes is of DenseMap<StringRef, HeaderType>, so we don't need
to allocate a temporary instance of std::string.


>From 053ad9fa370c34747a6aea8330f12633dcc96eea Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 6 Nov 2024 08:58:39 -0800
Subject: [PATCH] [InstallAPI] Call DenseMap::find without constructing
 std::string (NFC)

KnownIncludes is of DenseMap<StringRef, HeaderType>, so we don't need
to allocate a temporary instance of std::string.
---
 clang/lib/InstallAPI/Frontend.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/InstallAPI/Frontend.cpp b/clang/lib/InstallAPI/Frontend.cpp
index 2ebe72bf021cf9..9e8c60fbda3d00 100644
--- a/clang/lib/InstallAPI/Frontend.cpp
+++ b/clang/lib/InstallAPI/Frontend.cpp
@@ -94,7 +94,7 @@ InstallAPIContext::findAndRecordFile(const FileEntry *FE,
   // included. This is primarily to resolve headers found
   // in a different location than what passed directly as input.
   StringRef IncludeName = PP.getHeaderSearchInfo().getIncludeNameForHeader(FE);
-  auto BackupIt = KnownIncludes.find(IncludeName.str());
+  auto BackupIt = KnownIncludes.find(IncludeName);
   if (BackupIt != KnownIncludes.end()) {
     KnownFiles[FE] = BackupIt->second;
     return BackupIt->second;



More information about the cfe-commits mailing list