C#: Minor performance rewrite

This commit is contained in:
Tom Hvitved
2019-07-02 13:11:27 +02:00
parent f91e460869
commit 16b6791914

View File

@@ -1202,22 +1202,14 @@ module ControlFlow {
c instanceof ExitCompletion
)
or
// If the `finally` block completes normally, it resumes any non-normal
result = lastTryStmtFinally(ts, c, any(NormalCompletion nc))
or
// If the `finally` block completes normally, it inherits any non-normal
// completion that was current before the `finally` block was entered
exists(NormalCompletion c0 |
result = lastTryStmtFinally(ts, c0) and
(
exists(getBlockOrCatchFinallyPred(ts, any(NormalCompletion nc))) and
c = c0
or
exists(AbnormalCompletion ac, InheritedCompletion ic |
c = ic and
exists(getBlockOrCatchFinallyPred(ts, ac)) and
ac.getInheritedCompletion() = ic.getInheritedCompletion() and
ic.getUnderlyingCompletion() = c0
)
c = any(InheritedCompletion ic |
result = lastTryStmtFinally(ts, ic.getUnderlyingCompletion(),
ic.getInheritedCompletion())
)
)
)
}
@@ -1245,11 +1237,6 @@ module ControlFlow {
result = last(ts.getBlock(), c)
}
pragma[nomagic]
private ControlFlowElement lastTryStmtFinally(TryStmt ts, Completion c) {
result = last(ts.getFinally(), c)
}
pragma[nomagic]
private ControlFlowElement lastLastCatchClause(CatchClause cc, Completion c) {
cc.isLast() and
@@ -1292,6 +1279,22 @@ module ControlFlow {
result = lastLastCatchClause(ts.getACatchClause(), c)
}
pragma[nomagic]
private ControlFlowElement lastTryStmtFinally0(TryStmt ts, Completion c) {
result = last(ts.getFinally(), c)
}
pragma[nomagic]
ControlFlowElement lastTryStmtFinally(
TryStmt ts, NormalCompletion finally, Completion inherited
) {
result = lastTryStmtFinally0(ts, finally) and
exists(Completion c0 | exists(getBlockOrCatchFinallyPred(ts, c0)) |
inherited = c0.(NormalCompletion) or
inherited = c0.(AbnormalCompletion).getInheritedCompletion()
)
}
/**
* Holds if the `try` block that catch clause `last` belongs to may throw an
* exception of type `c`, where no `catch` clause is guaranteed to catch it.