From: Richard Howell Date: Thu, 16 Sep 2021 21:01:30 +0000 (-0700) Subject: [clang][NFC] refactor GlobalMethodPool to encapsulate its map X-Git-Tag: upstream/15.0.7~31292 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e6020b2a42245d888e941eba66fbce9d0c4ab0a8;p=platform%2Fupstream%2Fllvm.git [clang][NFC] refactor GlobalMethodPool to encapsulate its map This refactor changes the GlobalMethodPool to a class that contains the DenseMap of methods. This is to allow for the addition of a separate DenseSet in a follow-up diff that will handle method de-duplication when inserting methods into the global method pool. Changes: - the `GlobalMethods` pair becomes `GlobalMethodPool::Lists` - the `GlobalMethodPool` becomes a class containing the `DenseMap` of methods - pass through methods are added to maintain most of the existing code without changing `MethodPool` -> `MethodPool.Methods` everywhere Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D109898 --- diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 6214ef6..ebe2438 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -1419,8 +1419,22 @@ public: const llvm::MapVector & getMismatchingDeleteExpressions() const; - typedef std::pair GlobalMethods; - typedef llvm::DenseMap GlobalMethodPool; + class GlobalMethodPool { + public: + using Lists = std::pair; + using iterator = llvm::DenseMap::iterator; + iterator begin() { return Methods.begin(); } + iterator end() { return Methods.end(); } + iterator find(Selector Sel) { return Methods.find(Sel); } + std::pair insert(std::pair &&Val) { + return Methods.insert(Val); + } + int count(Selector Sel) const { return Methods.count(Sel); } + bool empty() const { return Methods.empty(); } + + private: + llvm::DenseMap Methods; + }; /// Method Pool - allows efficient lookup when typechecking messages to "id". /// We need to maintain a list, since selectors can have differing signatures diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index e0f8c6e..f19a041 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -3427,8 +3427,10 @@ void Sema::AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, GlobalMethodPool::iterator Pos = MethodPool.find(Method->getSelector()); if (Pos == MethodPool.end()) - Pos = MethodPool.insert(std::make_pair(Method->getSelector(), - GlobalMethods())).first; + Pos = MethodPool + .insert(std::make_pair(Method->getSelector(), + GlobalMethodPool::Lists())) + .first; Method->setDefined(impl); @@ -3636,7 +3638,7 @@ ObjCMethodDecl *Sema::LookupImplementedMethodInGlobalPool(Selector Sel) { if (Pos == MethodPool.end()) return nullptr; - GlobalMethods &Methods = Pos->second; + GlobalMethodPool::Lists &Methods = Pos->second; for (const ObjCMethodList *Method = &Methods.first; Method; Method = Method->getNext()) if (Method->getMethod() && diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 3dbcea7..b015ca1 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -8208,8 +8208,9 @@ void ASTReader::ReadMethodPool(Selector Sel) { return; Sema &S = *getSema(); - Sema::GlobalMethodPool::iterator Pos - = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; + Sema::GlobalMethodPool::iterator Pos = + S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethodPool::Lists())) + .first; Pos->second.first.setBits(Visitor.getInstanceBits()); Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl());