Index: clang/include/clang/AST/DeclBase.h =================================================================== --- clang/include/clang/AST/DeclBase.h +++ clang/include/clang/AST/DeclBase.h @@ -1225,38 +1225,34 @@ /// single result (with no stable storage) or a collection of results (with /// stable storage provided by the lookup table). class DeclContextLookupResult { - using ResultTy = std::list; + using ResultTy = ArrayRef; - llvm::iterator_range Result; + ResultTy Result; // If there is only one lookup result, it would be invalidated by // reallocations of the name table, so store it separately. NamedDecl *Single = nullptr; - static ResultTy const SingleElementDummyList; + static NamedDecl *const SingleElementDummyList; public: - DeclContextLookupResult() - : Result(llvm::make_range(SingleElementDummyList.end(), - SingleElementDummyList.end())) {} - DeclContextLookupResult(const ResultTy &Result) - : Result(llvm::make_range(Result.begin(), Result.end())) {} - + DeclContextLookupResult() = default; + DeclContextLookupResult(ArrayRef Result) + : Result(Result) {} DeclContextLookupResult(NamedDecl *Single) - : Result(llvm::make_range(SingleElementDummyList.begin(), - SingleElementDummyList.end())), Single(Single) {} + : Result(SingleElementDummyList), Single(Single) {} class iterator; using IteratorBase = - llvm::iterator_adaptor_base; + llvm::iterator_adaptor_base; class iterator : public IteratorBase { value_type SingleElement; public: - explicit iterator(ResultTy::const_iterator Pos, value_type Single = nullptr) + explicit iterator(pointer Pos, value_type Single = nullptr) : IteratorBase(Pos), SingleElement(Single) {} reference operator*() const { @@ -1272,21 +1268,15 @@ iterator end() const { return iterator(Result.end(), Single); } bool empty() const { return Result.empty(); } - size_t size() const { - if (empty()) - return 0; - return Single ? 1 : std::distance(begin(), end()); - }; - reference front() const { return Single ? Single : *Result.begin(); } - reference back() const { return Single ? Single : *(--Result.end()); } + pointer data() const { return Single ? &Single : Result.data(); } + size_t size() const { return Single ? 1 : Result.size(); } + reference front() const { return Single ? Single : Result.front(); } + reference back() const { return Single ? Single : Result.back(); } + reference operator[](size_t N) const { return Single ? Single : Result[N]; } // FIXME: Remove this from the interface DeclContextLookupResult slice(size_t N) const { - assert(size() >= N); - DeclContextLookupResult Sliced; - auto I = Result.begin(); - std::advance(I, N); - Sliced.Result = llvm::make_range(I, Result.end()); + DeclContextLookupResult Sliced = Result.slice(N); Sliced.Single = Single; return Sliced; } Index: clang/include/clang/AST/DeclContextInternals.h =================================================================== --- clang/include/clang/AST/DeclContextInternals.h +++ clang/include/clang/AST/DeclContextInternals.h @@ -21,9 +21,9 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/SmallVector.h" #include #include -#include namespace clang { @@ -33,7 +33,7 @@ /// one entry. struct StoredDeclsList { /// When in vector form, this is what the Data pointer points to. - using DeclsTy = std::list; + using DeclsTy = SmallVector; /// A collection of declarations, with a flag to indicate if we have /// further external declarations. @@ -221,7 +221,7 @@ (*I)->getIdentifierNamespace() == Decl::IDNS_Using) ++I; } - Vec.push_back(I, D); + Vec.insert(I, D); // All other declarations go at the end of the list, but before any // tag declarations. But we can be clever about tag declarations Index: clang/lib/ARCMigrate/ObjCMT.cpp =================================================================== --- clang/lib/ARCMigrate/ObjCMT.cpp +++ clang/lib/ARCMigrate/ObjCMT.cpp @@ -622,7 +622,7 @@ Property->getQueryKind())) return false; } - else if (auto *ClassProperty = dyn_cast(R.front())) { + else if (ObjCPropertyDecl *ClassProperty = dyn_cast(R[0])) { if ((ClassProperty->getPropertyAttributes() != Property->getPropertyAttributes()) || !Ctx.hasSameType(ClassProperty->getType(), Property->getType())) @@ -650,7 +650,7 @@ bool match = false; HasAtleastOneRequiredMethod = true; for (unsigned I = 0, N = R.size(); I != N; ++I) - if (ObjCMethodDecl *ImpMD = dyn_cast(R.front())) + if (ObjCMethodDecl *ImpMD = dyn_cast(R[0])) if (Ctx.ObjCMethodsAreEqual(MD, ImpMD)) { match = true; break; Index: clang/lib/AST/DeclBase.cpp =================================================================== --- clang/lib/AST/DeclBase.cpp +++ clang/lib/AST/DeclBase.cpp @@ -37,7 +37,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" @@ -1546,8 +1545,7 @@ assert(Pos != Map->end() && "no lookup entry for decl"); // Remove the decl only if it is contained. StoredDeclsList::DeclsTy *Vec = Pos->second.getAsVector(); - if ((Vec && llvm::is_contained(*Vec, ND)) || - Pos->second.getAsDecl() == ND) + if ((Vec && is_contained(*Vec, ND)) || Pos->second.getAsDecl() == ND) Pos->second.remove(ND); } } while (DC->isTransparentContext() && (DC = DC->getParent())); @@ -1665,8 +1663,7 @@ } } -DeclContextLookupResult::ResultTy -const DeclContextLookupResult::SingleElementDummyList = { nullptr }; +NamedDecl *const DeclContextLookupResult::SingleElementDummyList = nullptr; DeclContext::lookup_result DeclContext::lookup(DeclarationName Name) const { Index: clang/lib/AST/ExternalASTMerger.cpp =================================================================== --- clang/lib/AST/ExternalASTMerger.cpp +++ clang/lib/AST/ExternalASTMerger.cpp @@ -77,7 +77,7 @@ // nothing (rather than a possibly-inaccurate guess) here. return nullptr; } else { - NamedDecl *SearchResultDecl = SearchResult.front(); + NamedDecl *SearchResultDecl = SearchResult[0]; if (isa(SearchResultDecl) && SearchResultDecl->getKind() == DC->getDeclKind()) return cast(SearchResultDecl)->getPrimaryContext(); Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -4106,9 +4106,13 @@ IdentifierInfo *MemberOrBase) { if (SS.getScopeRep() || TemplateTypeTy) return nullptr; - for (auto *D : ClassDecl->lookup(MemberOrBase)) - if (isa(D) || isa(D)) - return cast(D); + DeclContext::lookup_result Result = ClassDecl->lookup(MemberOrBase); + if (Result.empty()) + return nullptr; + ValueDecl *Member; + if ((Member = dyn_cast(Result.front())) || + (Member = dyn_cast(Result.front()))) + return Member; return nullptr; } @@ -15077,9 +15081,9 @@ // different modules). assert((getLangOpts().Modules || (!Lookup.empty() && Lookup.size() <= 2)) && "more than two lookup results for field name"); - FieldDecl *Pattern = dyn_cast(Lookup.back()); + FieldDecl *Pattern = dyn_cast(Lookup[0]); if (!Pattern) { - assert(isa(Lookup.back()) && + assert(isa(Lookup[0]) && "cannot have other non-field member with same name"); for (auto L : Lookup) if (isa(L)) { Index: clang/lib/Sema/SemaObjCProperty.cpp =================================================================== --- clang/lib/Sema/SemaObjCProperty.cpp +++ clang/lib/Sema/SemaObjCProperty.cpp @@ -112,8 +112,9 @@ return; // Look for a property with the same name. - for (auto *R : Proto->lookup(Prop->getDeclName())) { - if (ObjCPropertyDecl *ProtoProp = dyn_cast(R)) { + DeclContext::lookup_result R = Proto->lookup(Prop->getDeclName()); + for (unsigned I = 0, N = R.size(); I != N; ++I) { + if (ObjCPropertyDecl *ProtoProp = dyn_cast(R[I])) { S.DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(), true); return; } @@ -232,8 +233,9 @@ bool FoundInSuper = false; ObjCInterfaceDecl *CurrentInterfaceDecl = IFace; while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) { - for (auto *R : Super->lookup(Res->getDeclName())) { - if (ObjCPropertyDecl *SuperProp = dyn_cast(R)) { + DeclContext::lookup_result R = Super->lookup(Res->getDeclName()); + for (unsigned I = 0, N = R.size(); I != N; ++I) { + if (ObjCPropertyDecl *SuperProp = dyn_cast(R[I])) { DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false); FoundInSuper = true; break; @@ -1148,7 +1150,7 @@ for (auto *Ext : IDecl->known_extensions()) { DeclContext::lookup_result R = Ext->lookup(property->getDeclName()); if (!R.empty()) - if (auto *ExtProp = dyn_cast(R.front())) { + if (ObjCPropertyDecl *ExtProp = dyn_cast(R[0])) { PIkind = ExtProp->getPropertyAttributesAsWritten(); if (PIkind & ObjCPropertyAttribute::kind_readwrite) { ReadWriteProperty = true; Index: clang/lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiate.cpp +++ clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -3414,7 +3414,7 @@ Instantiation->getTemplateInstantiationPattern(); DeclContext::lookup_result Lookup = ClassPattern->lookup(Field->getDeclName()); - FieldDecl *Pattern = cast(Lookup.back()); + FieldDecl *Pattern = cast(Lookup.front()); InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern, TemplateArgs); }