mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Merge pull request #1335 from EdoDodo/optimise-preprocessor
C++: Optimise quadratic code in PreprocessorBranchDirective
This commit is contained in:
@@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user