Skip to content

Commit 9852ff5

Browse files
committed
[Review] Use try_emplace and update missing insert(, new )
1 parent fe30b3c commit 9852ff5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/SPIRV/libSPIRV/SPIRVModule.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void SPIRVModuleImpl::addCapability(SPIRVCapabilityKind Cap) {
784784
SPIRVDBG(spvdbgs() << "addCapability: " << SPIRVCapabilityNameMap::map(Cap)
785785
<< '\n');
786786

787-
auto [It, Inserted] = CapMap.insert(std::make_pair(Cap, nullptr));
787+
auto [It, Inserted] = CapMap.try_emplace(Cap);
788788
if (!Inserted)
789789
return;
790790

@@ -802,10 +802,11 @@ void SPIRVModuleImpl::addCapability(SPIRVCapabilityKind Cap) {
802802

803803
void SPIRVModuleImpl::addCapabilityInternal(SPIRVCapabilityKind Cap) {
804804
if (AutoAddCapability) {
805-
if (hasCapability(Cap))
805+
auto [It, Inserted] = CapMap.try_emplace(Cap);
806+
if (!Inserted)
806807
return;
807808

808-
CapMap.insert(std::make_pair(Cap, new SPIRVCapability(this, Cap)));
809+
It->second = std::make_unique<SPIRVCapability>(this, Cap);
809810
}
810811
}
811812

@@ -815,7 +816,7 @@ void SPIRVModuleImpl::addConditionalCapability(SPIRVId Condition,
815816
<< SPIRVCapabilityNameMap::map(Cap)
816817
<< ", condition: " << Condition << '\n');
817818
auto Key = std::make_pair(Condition, Cap);
818-
auto [It, Inserted] = ConditionalCapMap.insert({Key, nullptr});
819+
auto [It, Inserted] = ConditionalCapMap.try_emplace(Key);
819820
if (!Inserted) {
820821
return;
821822
}

0 commit comments

Comments
 (0)