[llvm] [TextAPI] Use MapVector::try_emplace (NFC) (PR #143564)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 10 08:57:06 PDT 2025


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

- try_emplace(Key) is shorter than insert({Key, nullptr}).
- try_emplace performs value initialization without value parameters.
- We overwrite values on successful insertion anyway.


>From 19f10f16ffe08fd0d3e2aabeec02e0cd54dcfdd6 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 9 Jun 2025 09:47:08 -0700
Subject: [PATCH] [TextAPI] Use MapVector::try_emplace (NFC)

- try_emplace(Key) is shorter than insert({Key, nullptr}).
- try_emplace performs value initialization without value parameters.
- We overwrite values on successful insertion anyway.
---
 llvm/lib/TextAPI/RecordsSlice.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/TextAPI/RecordsSlice.cpp b/llvm/lib/TextAPI/RecordsSlice.cpp
index 1500b8752115a..1d04b63606522 100644
--- a/llvm/lib/TextAPI/RecordsSlice.cpp
+++ b/llvm/lib/TextAPI/RecordsSlice.cpp
@@ -259,7 +259,7 @@ ObjCInterfaceRecord::getObjCCategories() const {
 
 ObjCIVarRecord *ObjCContainerRecord::addObjCIVar(StringRef IVar,
                                                  RecordLinkage Linkage) {
-  auto Result = IVars.insert({IVar, nullptr});
+  auto Result = IVars.try_emplace(IVar);
   if (Result.second)
     Result.first->second = std::make_unique<ObjCIVarRecord>(IVar, Linkage);
   return Result.first->second.get();



More information about the llvm-commits mailing list