Skip to content

Commit 8018db3

Browse files
authored
Merge pull request #2474 from hvitved/csharp/dispatch-perf
C#: Improve performance of dispatch library
2 parents b752a6c + c845a1b commit 8018db3

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

csharp/ql/src/semmle/code/csharp/dispatch/Dispatch.qll

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,16 @@ private module Internal {
190190
abstract RuntimeCallable getADynamicTarget();
191191
}
192192

193+
pragma[noinline]
194+
private predicate hasOverrider(OverridableCallable oc, ValueOrRefType t) {
195+
exists(oc.getAnOverrider(t))
196+
}
197+
193198
pragma[noinline]
194199
private predicate hasCallable(OverridableCallable source, ValueOrRefType t, OverridableCallable c) {
195200
c.getSourceDeclaration() = source and
196201
t.hasCallable(c) and
202+
hasOverrider(c, t) and
197203
hasQualifierTypeOverridden0(t, _) and
198204
hasQualifierTypeOverridden1(source, _)
199205
}
@@ -215,15 +221,19 @@ private module Internal {
215221

216222
pragma[noinline]
217223
private predicate hasQualifierTypeOverridden0(ValueOrRefType t, DispatchMethodOrAccessorCall call) {
218-
exists(Type t0 | t0 = getAPossibleType(call.getQualifier(), false) |
219-
t = t0
220-
or
221-
Unification::subsumes(t0, t)
224+
hasOverrider(_, t) and
225+
(
226+
exists(Type t0 | t0 = getAPossibleType(call.getQualifier(), false) |
227+
t = t0
228+
or
229+
Unification::subsumes(t0, t)
230+
or
231+
t = t0.(Unification::UnconstrainedTypeParameter).getAnUltimatelySuppliedType()
232+
)
222233
or
223-
t = t0.(Unification::UnconstrainedTypeParameter).getAnUltimatelySuppliedType()
234+
constrainedTypeParameterQualifierTypeSubsumes(t,
235+
getAConstrainedTypeParameterQualifierType(call))
224236
)
225-
or
226-
constrainedTypeParameterQualifierTypeSubsumes(t, getAConstrainedTypeParameterQualifierType(call))
227237
}
228238

229239
pragma[noinline]

0 commit comments

Comments
 (0)