-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Sema] Declare GlobalMethodPool with using (NFC) #109437
[Sema] Declare GlobalMethodPool with using (NFC) #109437
Conversation
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.
|
@llvm/pr-subscribers-clang-modules Author: Kazu Hirata (kazutakahirata) ChangesGlobalMethodPool is a wrapper around DenseMap that does not add 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 Full diff: https://github.com/llvm/llvm-project/pull/109437.diff 3 Files Affected:
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 differing 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 7efcc81e194d95..47a286be2303fd 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) {
|
|
@llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesGlobalMethodPool is a wrapper around DenseMap that does not add 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 Full diff: https://github.com/llvm/llvm-project/pull/109437.diff 3 Files Affected:
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 differing 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 7efcc81e194d95..47a286be2303fd 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) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
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.