Skip to content

Commit ba67ea0

Browse files
committed
C#: Fix performance issue with UselessNullCoalescingExpression query.
1 parent 432ac7a commit ba67ea0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

csharp/ql/src/Language Abuse/UselessNullCoalescingExpression.ql

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@
1414
import csharp
1515
import semmle.code.csharp.commons.StructuralComparison
1616

17+
pragma[noinline]
18+
private predicate same(AssignableAccess x, AssignableAccess y) {
19+
exists(NullCoalescingExpr nce |
20+
x = nce.getLeftOperand() and
21+
y = nce.getRightOperand().getAChildExpr*()
22+
) and
23+
sameGvn(x, y)
24+
}
25+
1726
private predicate uselessNullCoalescingExpr(NullCoalescingExpr nce) {
18-
forex(AssignableAccess y |
19-
y = nce.getRightOperand().getAChildExpr*() and sameGvn(nce.getLeftOperand(), y)
20-
|
21-
y instanceof AssignableRead and not y.isRefArgument()
27+
exists(AssignableAccess x |
28+
nce.getLeftOperand() = x and
29+
forex(AssignableAccess y | same(x, y) | y instanceof AssignableRead and not y.isRefArgument())
2230
)
2331
}
2432

0 commit comments

Comments
 (0)