Skip to content

Commit 3a808ff

Browse files
committed
[AST] Limit ValueDecl::canBeAccessByDynamicLookup() dependencies.
This function was checking isObjC() first, which is potentially expensive to compute, and *then* performing structural checks. Re-order the checking so that we perform the (cheap, lower-dependency) structural checks first, and then semantic isObjC() check later.
1 parent aa8b3c4 commit 3a808ff

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/AST/Decl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,14 +2013,10 @@ bool ValueDecl::canBeAccessedByDynamicLookup() const {
20132013
if (!hasName())
20142014
return false;
20152015

2016-
// Dynamic lookup can only find @objc members.
2017-
if (!isObjC())
2018-
return false;
2019-
20202016
// Dynamic lookup can only find class and protocol members, or extensions of
20212017
// classes.
20222018
auto nominalDC =
2023-
getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
2019+
getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
20242020
if (!nominalDC ||
20252021
(!isa<ClassDecl>(nominalDC) && !isa<ProtocolDecl>(nominalDC)))
20262022
return false;
@@ -2031,10 +2027,14 @@ bool ValueDecl::canBeAccessedByDynamicLookup() const {
20312027
return false;
20322028

20332029
// Dynamic lookup can find functions, variables, and subscripts.
2034-
if (isa<FuncDecl>(this) || isa<VarDecl>(this) || isa<SubscriptDecl>(this))
2035-
return true;
2030+
if (!isa<FuncDecl>(this) && !isa<VarDecl>(this) && !isa<SubscriptDecl>(this))
2031+
return false;
20362032

2037-
return false;
2033+
// Dynamic lookup can only find @objc members.
2034+
if (!isObjC())
2035+
return false;
2036+
2037+
return true;
20382038
}
20392039

20402040
ArrayRef<ValueDecl *>

0 commit comments

Comments
 (0)