Skip to content

Commit 69dbf46

Browse files
[Sema] Avoid repeated hash lookups (NFC) (#109375)
GlobalMethodPool, the type of MethodPool, is a type wrapping DenseMap and exposes only a subset of the DenseMap methods. This patch adds operator[] to GlobalMethodPool so that we can avoid repeated hash lookups. I don't bother using references or rvalue references in operator[] because Selector, the key type, is small and trivially copyable. Note that Selector is a class that wraps a PointerUnion.
1 parent 9f8f1d9 commit 69dbf46

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

clang/include/clang/Sema/SemaObjC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class SemaObjC : public SemaBase {
218218
std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) {
219219
return Methods.insert(Val);
220220
}
221+
Lists &operator[](Selector Key) { return Methods[Key]; }
221222
int count(Selector Sel) const { return Methods.count(Sel); }
222223
bool empty() const { return Methods.empty(); }
223224

clang/lib/Sema/SemaDeclObjC.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,16 +3441,11 @@ void SemaObjC::AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl,
34413441
if (SemaRef.ExternalSource)
34423442
ReadMethodPool(Method->getSelector());
34433443

3444-
GlobalMethodPool::iterator Pos = MethodPool.find(Method->getSelector());
3445-
if (Pos == MethodPool.end())
3446-
Pos = MethodPool
3447-
.insert(std::make_pair(Method->getSelector(),
3448-
GlobalMethodPool::Lists()))
3449-
.first;
3444+
auto &Lists = MethodPool[Method->getSelector()];
34503445

34513446
Method->setDefined(impl);
34523447

3453-
ObjCMethodList &Entry = instance ? Pos->second.first : Pos->second.second;
3448+
ObjCMethodList &Entry = instance ? Lists.first : Lists.second;
34543449
addMethodToGlobalList(&Entry, Method);
34553450
}
34563451

0 commit comments

Comments
 (0)