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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp (+1-3) 


``````````diff
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;

``````````

</details>


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


More information about the cfe-commits mailing list