[clang] Use *Map::try_emplace (NFC) (#140477)
We can simplify the code with *Map::try_emplace where we need default-constructed values while avoding calling constructors when keys are already present.
This commit is contained in:
@@ -1924,8 +1924,7 @@ DeclContext::lookupImpl(DeclarationName Name,
|
||||
Map = CreateStoredDeclsMap(getParentASTContext());
|
||||
|
||||
// If we have a lookup result with no external decls, we are done.
|
||||
std::pair<StoredDeclsMap::iterator, bool> R =
|
||||
Map->insert(std::make_pair(Name, StoredDeclsList()));
|
||||
std::pair<StoredDeclsMap::iterator, bool> R = Map->try_emplace(Name);
|
||||
if (!R.second && !R.first->second.hasExternalDecls())
|
||||
return R.first->second.getLookupResult();
|
||||
|
||||
|
||||
@@ -150,8 +150,7 @@ void DiagnosticsEngine::Reset(bool soft /*=false*/) {
|
||||
|
||||
DiagnosticMapping &
|
||||
DiagnosticsEngine::DiagState::getOrAddMapping(diag::kind Diag) {
|
||||
std::pair<iterator, bool> Result =
|
||||
DiagMap.insert(std::make_pair(Diag, DiagnosticMapping()));
|
||||
std::pair<iterator, bool> Result = DiagMap.try_emplace(Diag);
|
||||
|
||||
// Initialize the entry if we added it.
|
||||
if (Result.second) {
|
||||
|
||||
@@ -1726,7 +1726,7 @@ void SourceManager::computeMacroArgsCache(MacroArgsMap &MacroArgsCache,
|
||||
assert(FID.isValid());
|
||||
|
||||
// Initially no macro argument chunk is present.
|
||||
MacroArgsCache.insert(std::make_pair(0, SourceLocation()));
|
||||
MacroArgsCache.try_emplace(0);
|
||||
|
||||
int ID = FID.ID;
|
||||
while (true) {
|
||||
|
||||
@@ -11350,7 +11350,7 @@ CGOpenMPRuntime::LastprivateConditionalRAII::LastprivateConditionalRAII(
|
||||
LastprivateConditionalData &Data =
|
||||
CGM.getOpenMPRuntime().LastprivateConditionalStack.emplace_back();
|
||||
for (const Decl *VD : NeedToAddForLPCsAsDisabled)
|
||||
Data.DeclToUniqueName.insert(std::make_pair(VD, SmallString<16>()));
|
||||
Data.DeclToUniqueName.try_emplace(VD);
|
||||
Data.Fn = CGF.CurFn;
|
||||
Data.Disabled = true;
|
||||
}
|
||||
|
||||
@@ -1020,7 +1020,7 @@ llvm::Function *CGOpenMPRuntimeGPU::emitTeamsOutlinedFunction(
|
||||
for (const auto &Pair : MappedDeclsFields) {
|
||||
assert(Pair.getFirst()->isCanonicalDecl() &&
|
||||
"Expected canonical declaration");
|
||||
Data.insert(std::make_pair(Pair.getFirst(), MappedVarData()));
|
||||
Data.try_emplace(Pair.getFirst());
|
||||
}
|
||||
}
|
||||
Rt.emitGenericVarsProlog(CGF, Loc);
|
||||
@@ -2025,7 +2025,7 @@ void CGOpenMPRuntimeGPU::emitFunctionProlog(CodeGenFunction &CGF,
|
||||
DeclToAddrMapTy &Data = I->getSecond().LocalVarData;
|
||||
for (const ValueDecl *VD : VarChecker.getEscapedDecls()) {
|
||||
assert(VD->isCanonicalDecl() && "Expected canonical declaration");
|
||||
Data.insert(std::make_pair(VD, MappedVarData()));
|
||||
Data.try_emplace(VD);
|
||||
}
|
||||
if (!NeedToDelayGlobalization) {
|
||||
emitGenericVarsProlog(CGF, D->getBeginLoc());
|
||||
|
||||
@@ -711,7 +711,7 @@ void Preprocessor::EnterSubmodule(Module *M, SourceLocation ImportLoc,
|
||||
ModMap.resolveConflicts(M, /*Complain=*/false);
|
||||
|
||||
// If this is the first time we've entered this module, set up its state.
|
||||
auto R = Submodules.insert(std::make_pair(M, SubmoduleState()));
|
||||
auto R = Submodules.try_emplace(M);
|
||||
auto &State = R.first->second;
|
||||
bool FirstTime = R.second;
|
||||
if (FirstTime) {
|
||||
|
||||
@@ -319,7 +319,7 @@ Preprocessor::macro_begin(bool IncludeExternalMacros) const {
|
||||
|
||||
// Make sure we cover all macros in visible modules.
|
||||
for (const ModuleMacro &Macro : ModuleMacros)
|
||||
CurSubmoduleState->Macros.insert(std::make_pair(Macro.II, MacroState()));
|
||||
CurSubmoduleState->Macros.try_emplace(Macro.II);
|
||||
|
||||
return CurSubmoduleState->Macros.begin();
|
||||
}
|
||||
|
||||
@@ -20342,7 +20342,7 @@ bool Sema::IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val,
|
||||
assert(ED->isClosedFlag() && "looking for value in non-flag or open enum");
|
||||
assert(ED->isCompleteDefinition() && "expected enum definition");
|
||||
|
||||
auto R = FlagBitsCache.insert(std::make_pair(ED, llvm::APInt()));
|
||||
auto R = FlagBitsCache.try_emplace(ED);
|
||||
llvm::APInt &FlagBits = R.first->second;
|
||||
|
||||
if (R.second) {
|
||||
|
||||
Reference in New Issue
Block a user