[clang-tools-extra] 33ceb2d - [clang-tidy] Avoid repeated hash lookups (NFC) (#107490)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 5 19:04:33 PDT 2024


Author: Kazu Hirata
Date: 2024-09-05T19:04:30-07:00
New Revision: 33ceb2dd7596a05277fd246865862df6b03cf976

URL: https://github.com/llvm/llvm-project/commit/33ceb2dd7596a05277fd246865862df6b03cf976
DIFF: https://github.com/llvm/llvm-project/commit/33ceb2dd7596a05277fd246865862df6b03cf976.diff

LOG: [clang-tidy] Avoid repeated hash lookups (NFC) (#107490)

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index 5f046c502eb383..e516b71088425b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -67,9 +67,7 @@ static bool canAdvanceAssignment(AssignedLevel Level) {
 static void updateAssignmentLevel(
     const FieldDecl *Field, const Expr *Init, const CXXConstructorDecl *Ctor,
     llvm::DenseMap<const FieldDecl *, AssignedLevel> &AssignedFields) {
-  auto It = AssignedFields.find(Field);
-  if (It == AssignedFields.end())
-    It = AssignedFields.insert({Field, AssignedLevel::None}).first;
+  auto It = AssignedFields.try_emplace(Field, AssignedLevel::None).first;
 
   if (!canAdvanceAssignment(It->second))
     // fast path for already decided field.


        


More information about the cfe-commits mailing list