mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
C++: Optimize SubBasicBlock::getNode(int)
This commit is contained in:
@@ -97,16 +97,24 @@ class SubBasicBlock extends ControlFlowNodeBase {
|
||||
* start from 0, and the node at position 0 always exists and compares equal
|
||||
* to `this`.
|
||||
*/
|
||||
pragma[nomagic]
|
||||
ControlFlowNode getNode(int pos) {
|
||||
exists(BasicBlock bb | bb = this.getBasicBlock() |
|
||||
exists(int thisPos | this = bb.getNode(thisPos) |
|
||||
result = bb.getNode(thisPos + pos) and
|
||||
pos >= 0 and
|
||||
pos < this.getNumberOfNodes()
|
||||
exists(BasicBlock bb |
|
||||
exists(int outerPos |
|
||||
result = bb.getNode(outerPos) and
|
||||
pos = outerPosToInnerPos(bb, outerPos)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private int outerPosToInnerPos(BasicBlock bb, int posInBB) {
|
||||
exists(int thisPosInBB | this = bb.getNode(thisPosInBB) |
|
||||
posInBB = result + thisPosInBB and
|
||||
result = [ 0 .. this.getNumberOfNodes() - 1 ]
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets a control-flow node in this `SubBasicBlock`. */
|
||||
ControlFlowNode getANode() {
|
||||
result = this.getNode(_)
|
||||
|
||||
Reference in New Issue
Block a user