Skip to content

Commit 135b71b

Browse files
committed
Python: Apply performance fix by @hvitved
1 parent c7992f6 commit 135b71b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

python/ql/src/semmle/python/RegexTreeView.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ class RegExpSequence extends RegExpTerm, TRegExpSequence {
358358
override string getPrimaryQLClass() { result = "RegExpSequence" }
359359
}
360360

361+
pragma[nomagic]
362+
private int seqChildEnd(Regex re, int start, int end, int i) {
363+
result = seqChild(re, start, end, i).getEnd()
364+
}
365+
361366
// moved out so we can use it in the charpred
362367
private RegExpTerm seqChild(Regex re, int start, int end, int i) {
363368
re.sequence(start, end) and
@@ -372,7 +377,7 @@ private RegExpTerm seqChild(Regex re, int start, int end, int i) {
372377
or
373378
i > 0 and
374379
result.getRegex() = re and
375-
exists(int itemStart | itemStart = seqChild(re, start, end, i - 1).getEnd() |
380+
exists(int itemStart | itemStart = seqChildEnd(re, start, end, i - 1) |
376381
result.getStart() = itemStart and
377382
re.item(itemStart, result.getEnd())
378383
)
@@ -440,7 +445,7 @@ class RegExpEscape extends RegExpNormalChar {
440445
or
441446
this.getUnescaped() = "t" and result = "\t"
442447
or
443-
this.getUnescaped() = "f" and result = ""
448+
this.getUnescaped() = "f" and result = "\f"
444449
or
445450
isUnicode() and
446451
result = getUnicode()

0 commit comments

Comments
 (0)