Merge pull request #1335 from EdoDodo/optimise-preprocessor

C++: Optimise quadratic code in PreprocessorBranchDirective
This commit is contained in:
Geoffrey White
2019-05-20 15:58:33 +01:00
committed by GitHub

View File

@@ -73,14 +73,24 @@ abstract class PreprocessorBranchDirective extends PreprocessorDirective {
* `somePreprocessorBranchDirective`.
*/
PreprocessorBranchDirective getNext() {
getIf() = result.getIf() and
getLocation().getStartLine() < result.getLocation().getStartLine() and
not exists(PreprocessorBranchDirective other |
getIf() = other.getIf() and
getLocation().getStartLine() < other.getLocation().getStartLine() and
other.getLocation().getStartLine() < result.getLocation().getStartLine()
exists(PreprocessorBranch branch |
this.getIndexInBranch(branch) + 1 = result.getIndexInBranch(branch)
)
}
/**
* Gets the index of this branching directive within the matching #if,
* #ifdef or #ifndef.
*/
private int getIndexInBranch(PreprocessorBranch branch) {
this = rank[result](PreprocessorBranchDirective other |
other.getIf() = branch
|
other
order by
other.getLocation().getStartLine()
)
}
}
/**