[clang] [Format] Avoid repeated hash lookups (NFC) (PR #107962)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 9 20:46:28 PDT 2024


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

None

>From cc3832ba4c7c00de00346bde146420afeefc0b33 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 9 Sep 2024 07:33:21 -0700
Subject: [PATCH] [Format] Avoid repeated hash lookups (NFC)

---
 clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp b/clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
index c91d6251425eab..f4016320c58591 100644
--- a/clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
+++ b/clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
@@ -86,9 +86,7 @@ void ObjCPropertyAttributeOrderFixer::sortPropertyAttributes(
       Value = Tok->TokenText;
     }
 
-    auto It = SortOrderMap.find(Attribute);
-    if (It == SortOrderMap.end())
-      It = SortOrderMap.insert({Attribute, SortOrderMap.size()}).first;
+    auto It = SortOrderMap.try_emplace(Attribute, SortOrderMap.size()).first;
 
     // Sort the indices based on the priority stored in `SortOrderMap`.
     const auto Ordinal = It->second;



More information about the cfe-commits mailing list