Skip to content

Commit 182c62f

Browse files
authored
Merge pull request github#7838 from tausbn/python-fix-charset-performance-problem
Python: Fix performance issue in `charSet`
2 parents 5677681 + 67be20f commit 182c62f

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

python/ql/lib/semmle/python/regex.qll

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,11 @@ abstract class RegexString extends Expr {
198198

199199
/** Whether there is a character class, between start (inclusive) and end (exclusive) */
200200
predicate charSet(int start, int end) {
201-
exists(int inner_start, int inner_end |
201+
exists(int inner_start |
202202
this.char_set_start(start, inner_start) and
203203
not this.char_set_start(_, start)
204204
|
205-
end = inner_end + 1 and
206-
inner_end > inner_start and
207-
this.nonEscapedCharAt(inner_end) = "]" and
208-
not exists(int mid | this.nonEscapedCharAt(mid) = "]" | mid > inner_start and mid < inner_end)
205+
end - 1 = min(int i | this.nonEscapedCharAt(i) = "]" and inner_start < i)
209206
)
210207
}
211208

@@ -344,9 +341,7 @@ abstract class RegexString extends Expr {
344341
this.escapingChar(start) and
345342
this.getChar(start + 1) = "N" and
346343
this.getChar(start + 2) = "{" and
347-
this.getChar(end - 1) = "}" and
348-
end > start and
349-
not exists(int i | start + 2 < i and i < end - 1 | this.getChar(i) = "}")
344+
end - 1 = min(int i | start + 2 < i and this.getChar(i) = "}")
350345
}
351346

352347
/**

0 commit comments

Comments
 (0)