diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-25 00:49:42 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-25 00:49:42 +0000 |
commit | e171601ff68e51a10ac907299190a23076eb5002 (patch) | |
tree | 3381720e8a499a8f4c98a66dad0f084dcc10d168 /clang/lib/Serialization | |
parent | 44d2973b6f39040d012e96ebb422b60e2a4358c1 (diff) | |
download | bcm5719-llvm-e171601ff68e51a10ac907299190a23076eb5002.tar.gz bcm5719-llvm-e171601ff68e51a10ac907299190a23076eb5002.zip |
Rework the external Sema source's ReadMethodPool() so that it doesn't
return pre-built lists. Instead, it feeds the methods it deserializes
to Sema so that Sema can unique them, which keeps the chains shorter.
llvm-svn: 148889
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 683bc379cb9..6fa680a74f8 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -5216,30 +5216,6 @@ namespace clang { namespace serialization { llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; - /// \brief Build an ObjCMethodList from a vector of Objective-C method - /// declarations. - ObjCMethodList - buildObjCMethodList(const SmallVectorImpl<ObjCMethodDecl *> &Vec) const - { - ObjCMethodList List; - ObjCMethodList *Prev = 0; - for (unsigned I = 0, N = Vec.size(); I != N; ++I) { - if (!List.Method) { - // This is the first method, which is the easy case. - List.Method = Vec[I]; - Prev = &List; - continue; - } - - ObjCMethodList *Mem = - Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); - Prev->Next = new (Mem) ObjCMethodList(Vec[I], 0); - Prev = Prev->Next; - } - - return List; - } - public: ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel) : Reader(Reader), Sel(Sel) { } @@ -5273,28 +5249,44 @@ namespace clang { namespace serialization { } /// \brief Retrieve the instance methods found by this visitor. - ObjCMethodList getInstanceMethods() const { - return buildObjCMethodList(InstanceMethods); + ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { + return InstanceMethods; } /// \brief Retrieve the instance methods found by this visitor. - ObjCMethodList getFactoryMethods() const { - return buildObjCMethodList(FactoryMethods); + ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { + return FactoryMethods; } }; } } // end namespace clang::serialization -std::pair<ObjCMethodList, ObjCMethodList> -ASTReader::ReadMethodPool(Selector Sel) { +/// \brief Add the given set of methods to the method list. +static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, + ObjCMethodList &List) { + for (unsigned I = 0, N = Methods.size(); I != N; ++I) { + S.addMethodToGlobalList(&List, Methods[I]); + } +} + +void ASTReader::ReadMethodPool(Selector Sel) { ReadMethodPoolVisitor Visitor(*this, Sel); ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); - std::pair<ObjCMethodList, ObjCMethodList> Result; - Result.first = Visitor.getInstanceMethods(); - Result.second = Visitor.getFactoryMethods(); - if (!Result.first.Method && !Result.second.Method) + if (Visitor.getInstanceMethods().empty() && + Visitor.getFactoryMethods().empty()) { ++NumMethodPoolMisses; - return Result; + return; + } + + if (!getSema()) + return; + + Sema &S = *getSema(); + Sema::GlobalMethodPool::iterator Pos + = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; + + addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); + addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); } void ASTReader::ReadKnownNamespaces( |