[clang] [Format] Avoid repeated hash lookups (NFC) (PR #107962)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 10 01:54:12 PDT 2024
================
@@ -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;
----------------
owenca wrote:
My preference:
```suggestion
// Sort the indices based on the priority stored in `SortOrderMap`.
const auto Ordinal =
SortOrderMap.try_emplace(Attribute, SortOrderMap.size()).first->second;
```
And delete lines 89-91.
https://github.com/llvm/llvm-project/pull/107962
More information about the cfe-commits
mailing list