[clang] [Analysis] Avoid creating a temporary instance of std::string (NFC) (PR #151625)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 31 19:47:10 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

hasName takes StringRef, so we don't need to create a temporary
instance of std::string.


---
Full diff: https://github.com/llvm/llvm-project/pull/151625.diff


1 Files Affected:

- (modified) clang/lib/Analysis/RetainSummaryManager.cpp (+1-2) 


``````````diff
diff --git a/clang/lib/Analysis/RetainSummaryManager.cpp b/clang/lib/Analysis/RetainSummaryManager.cpp
index 987f894a2918f..688efe40875d2 100644
--- a/clang/lib/Analysis/RetainSummaryManager.cpp
+++ b/clang/lib/Analysis/RetainSummaryManager.cpp
@@ -147,8 +147,7 @@ static bool isSubclass(const Decl *D,
 
 static bool isExactClass(const Decl *D, StringRef ClassName) {
   using namespace ast_matchers;
-  DeclarationMatcher sameClassM =
-      cxxRecordDecl(hasName(std::string(ClassName)));
+  DeclarationMatcher sameClassM = cxxRecordDecl(hasName(ClassName));
   return !(match(sameClassM, *D, D->getASTContext()).empty());
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/151625


More information about the cfe-commits mailing list