Skip to content

Commit 30dd652

Browse files
[clang] Use *Map::try_emplace (NFC) (#143563)
- try_emplace(Key) is shorter than insert({Key, nullptr}). - try_emplace performs value initialization without value parameters. - We overwrite values on successful insertion anyway.
1 parent 1befb24 commit 30dd652

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ class IdentifierTable {
731731
/// introduce or modify an identifier. If they called get(), they would
732732
/// likely end up in a recursion.
733733
IdentifierInfo &getOwn(StringRef Name) {
734-
auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
734+
auto &Entry = *HashTable.try_emplace(Name).first;
735735

736736
IdentifierInfo *&II = Entry.second;
737737
if (II)

clang/include/clang/ExtractAPI/API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ APISet::createRecord(StringRef USR, StringRef Name,
14991499
CtorArgsContTy &&...CtorArgs) {
15001500
// Ensure USR refers to a String stored in the allocator.
15011501
auto USRString = copyString(USR);
1502-
auto Result = USRBasedLookupTable.insert({USRString, nullptr});
1502+
auto Result = USRBasedLookupTable.try_emplace(USRString);
15031503
RecordTy *Record;
15041504

15051505
// Create the record if it does not already exist

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
726726
auto *MPTy = cast<MemberPointerType>(Ty);
727727
if (!getCXXABI().isMemberPointerConvertible(MPTy)) {
728728
auto *C = MPTy->getMostRecentCXXRecordDecl()->getTypeForDecl();
729-
auto Insertion = RecordsWithOpaqueMemberPointers.insert({C, nullptr});
729+
auto Insertion = RecordsWithOpaqueMemberPointers.try_emplace(C);
730730
if (Insertion.second)
731731
Insertion.first->second = llvm::StructType::create(getLLVMContext());
732732
ResultType = Insertion.first->second;

clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ DependencyScanningFilesystemSharedCache::CacheShard::getOrEmplaceEntryForUID(
173173
llvm::sys::fs::UniqueID UID, llvm::vfs::Status Stat,
174174
std::unique_ptr<llvm::MemoryBuffer> Contents) {
175175
std::lock_guard<std::mutex> LockGuard(CacheLock);
176-
auto [It, Inserted] = EntriesByUID.insert({UID, nullptr});
176+
auto [It, Inserted] = EntriesByUID.try_emplace(UID);
177177
auto &CachedEntry = It->getSecond();
178178
if (Inserted) {
179179
CachedFileContents *StoredContents = nullptr;

0 commit comments

Comments
 (0)