Author: Kazu Hirata Date: 2023-06-03T09:37:36-07:00 New Revision: 8dc7647845a4357f6aee7ffe40839c97f2474d99
URL: https://github.com/llvm/llvm-project/commit/8dc7647845a4357f6aee7ffe40839c97f2474d99 DIFF: https://github.com/llvm/llvm-project/commit/8dc7647845a4357f6aee7ffe40839c97f2474d99.diff LOG: [AST] Use DenseMapBase::lookup (NFC) Added: Modified: clang/lib/AST/ASTContext.cpp clang/lib/AST/ASTImporter.cpp clang/lib/AST/ExternalASTMerger.cpp clang/lib/AST/Interp/Record.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index ef3242e81e65f..9af6fa67db1ef 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -499,10 +499,7 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl( // Any redeclarations of D that we haven't checked for comments yet? // We can't use DenseMap::iterator directly since it'd get invalid. auto LastCheckedRedecl = [this, CanonicalD]() -> const Decl * { - auto LookupRes = CommentlessRedeclChains.find(CanonicalD); - if (LookupRes != CommentlessRedeclChains.end()) - return LookupRes->second; - return nullptr; + return CommentlessRedeclChains.lookup(CanonicalD); }(); for (const auto Redecl : D->redecls()) { @@ -1523,11 +1520,7 @@ ASTContext::setTemplateOrSpecializationInfo(VarDecl *Inst, NamedDecl * ASTContext::getInstantiatedFromUsingDecl(NamedDecl *UUD) { - auto Pos = InstantiatedFromUsingDecl.find(UUD); - if (Pos == InstantiatedFromUsingDecl.end()) - return nullptr; - - return Pos->second; + return InstantiatedFromUsingDecl.lookup(UUD); } void @@ -1546,11 +1539,7 @@ ASTContext::setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern) { UsingEnumDecl * ASTContext::getInstantiatedFromUsingEnumDecl(UsingEnumDecl *UUD) { - auto Pos = InstantiatedFromUsingEnumDecl.find(UUD); - if (Pos == InstantiatedFromUsingEnumDecl.end()) - return nullptr; - - return Pos->second; + return InstantiatedFromUsingEnumDecl.lookup(UUD); } void ASTContext::setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, @@ -1561,12 +1550,7 @@ void ASTContext::setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, UsingShadowDecl * ASTContext::getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst) { - llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>::const_iterator Pos - = InstantiatedFromUsingShadowDecl.find(Inst); - if (Pos == InstantiatedFromUsingShadowDecl.end()) - return nullptr; - - return Pos->second; + return InstantiatedFromUsingShadowDecl.lookup(Inst); } void @@ -1577,12 +1561,7 @@ ASTContext::setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, } FieldDecl *ASTContext::getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field) { - llvm::DenseMap<FieldDecl *, FieldDecl *>::iterator Pos - = InstantiatedFromUnnamedFieldDecl.find(Field); - if (Pos == InstantiatedFromUnnamedFieldDecl.end()) - return nullptr; - - return Pos->second; + return InstantiatedFromUnnamedFieldDecl.lookup(Field); } void ASTContext::setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 6e2566b638609..6c04bc80270ae 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -8994,11 +8994,7 @@ Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { } Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { - auto Pos = ImportedDecls.find(FromD); - if (Pos != ImportedDecls.end()) - return Pos->second; - else - return nullptr; + return ImportedDecls.lookup(FromD); } TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { diff --git a/clang/lib/AST/ExternalASTMerger.cpp b/clang/lib/AST/ExternalASTMerger.cpp index a2ef270d7a9c5..8bad3b36244e1 100644 --- a/clang/lib/AST/ExternalASTMerger.cpp +++ b/clang/lib/AST/ExternalASTMerger.cpp @@ -187,10 +187,7 @@ class LazyASTImporter : public ASTImporter { /// Implements the ASTImporter interface for tracking back a declaration /// to its original declaration it came from. Decl *GetOriginalDecl(Decl *To) override { - auto It = ToOrigin.find(To); - if (It != ToOrigin.end()) - return It->second; - return nullptr; + return ToOrigin.lookup(To); } /// Whenever a DeclContext is imported, ensure that ExternalASTSource's origin @@ -541,4 +538,3 @@ void ExternalASTMerger::FindExternalLexicalDecls( return false; }); } - diff --git a/clang/lib/AST/Interp/Record.cpp b/clang/lib/AST/Interp/Record.cpp index c8cbdb314f512..909416e6e1a1a 100644 --- a/clang/lib/AST/Interp/Record.cpp +++ b/clang/lib/AST/Interp/Record.cpp @@ -44,9 +44,7 @@ const Record::Base *Record::getBase(QualType T) const { return nullptr; const RecordDecl *RD = T->getAs<RecordType>()->getDecl(); - if (auto It = BaseMap.find(RD); It != BaseMap.end()) - return It->second; - return nullptr; + return BaseMap.lookup(RD); } const Record::Base *Record::getVirtualBase(const RecordDecl *FD) const { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits