[clang] 533c7ff - [Sema] Declare GlobalMethodPool with using (NFC) (#109437)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 20 13:14:30 PDT 2024
Author: Kazu Hirata
Date: 2024-09-20T13:14:27-07:00
New Revision: 533c7ff2db6e7f78e34fc0cc1f6390645337d964
URL: https://github.com/llvm/llvm-project/commit/533c7ff2db6e7f78e34fc0cc1f6390645337d964
DIFF: https://github.com/llvm/llvm-project/commit/533c7ff2db6e7f78e34fc0cc1f6390645337d964.diff
LOG: [Sema] Declare GlobalMethodPool with using (NFC) (#109437)
GlobalMethodPool is a wrapper around DenseMap that does not add
anything except:
using Lists = std::pair<ObjCMethodList, ObjCMethodList>;
This patch removes the wrapper and switches to an alias with "using".
In ReadMethodPool in ASTReader.cpp, we can simplify:
insert(std::make_pair(Sel, SemaObjC::GlobalMethodPool::Lists()))
to:
try_emplace(Sel)
But then try_emplace(Sel).first->second is the same as operator[], so
this patch simplifies the rest of the function.
Added:
Modified:
clang/include/clang/Sema/SemaObjC.h
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Serialization/ASTReader.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/SemaObjC.h b/clang/include/clang/Sema/SemaObjC.h
index b868e9e7cd0aa9..9367c680953f71 100644
--- a/clang/include/clang/Sema/SemaObjC.h
+++ b/clang/include/clang/Sema/SemaObjC.h
@@ -208,23 +208,8 @@ class SemaObjC : public SemaBase {
/// of -Wselector.
llvm::MapVector<Selector, SourceLocation> ReferencedSelectors;
- class GlobalMethodPool {
- public:
- using Lists = std::pair<ObjCMethodList, ObjCMethodList>;
- using iterator = llvm::DenseMap<Selector, Lists>::iterator;
- iterator begin() { return Methods.begin(); }
- iterator end() { return Methods.end(); }
- iterator find(Selector Sel) { return Methods.find(Sel); }
- std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) {
- return Methods.insert(Val);
- }
- Lists &operator[](Selector Key) { return Methods[Key]; }
- int count(Selector Sel) const { return Methods.count(Sel); }
- bool empty() const { return Methods.empty(); }
-
- private:
- llvm::DenseMap<Selector, Lists> Methods;
- };
+ using GlobalMethodPool =
+ llvm::DenseMap<Selector, std::pair<ObjCMethodList, ObjCMethodList>>;
/// Method Pool - allows efficient lookup when typechecking messages to "id".
/// We need to maintain a list, since selectors can have
diff ering signatures
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 87be43b13813d3..d8cd09b8272930 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -3649,7 +3649,7 @@ ObjCMethodDecl *SemaObjC::LookupImplementedMethodInGlobalPool(Selector Sel) {
if (Pos == MethodPool.end())
return nullptr;
- GlobalMethodPool::Lists &Methods = Pos->second;
+ auto &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 f0af40cc172145..4df22ba63be6b8 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -8751,22 +8751,18 @@ void ASTReader::ReadMethodPool(Selector Sel) {
return;
Sema &S = *getSema();
- SemaObjC::GlobalMethodPool::iterator Pos =
- S.ObjC()
- .MethodPool
- .insert(std::make_pair(Sel, SemaObjC::GlobalMethodPool::Lists()))
- .first;
+ auto &Methods = S.ObjC().MethodPool[Sel];
- Pos->second.first.setBits(Visitor.getInstanceBits());
- Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl());
- Pos->second.second.setBits(Visitor.getFactoryBits());
- Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl());
+ Methods.first.setBits(Visitor.getInstanceBits());
+ Methods.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl());
+ Methods.second.setBits(Visitor.getFactoryBits());
+ Methods.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl());
// Add methods to the global pool *after* setting hasMoreThanOneDecl, since
// when building a module we keep every method individually and may need to
// update hasMoreThanOneDecl as we add the methods.
- addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first);
- addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second);
+ addMethodsToPool(S, Visitor.getInstanceMethods(), Methods.first);
+ addMethodsToPool(S, Visitor.getFactoryMethods(), Methods.second);
}
void ASTReader::updateOutOfDateSelector(Selector Sel) {
More information about the cfe-commits
mailing list