Skip to content

Commit 783233d

Browse files
authored
Merge pull request #6696 from yoff/python/copy-multiples-performance-fix-from-ruby
Python: Copy performance fix for `multiples` from ruby
2 parents 8022530 + d37c148 commit 783233d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -773,15 +773,18 @@ abstract class RegexString extends Expr {
773773
* string is empty.
774774
*/
775775
predicate multiples(int start, int end, string lower, string upper) {
776-
this.getChar(start) = "{" and
777-
this.getChar(end - 1) = "}" and
778-
exists(string inner | inner = this.getText().substring(start + 1, end - 1) |
779-
inner.regexpMatch("[0-9]+") and
776+
exists(string text, string match, string inner |
777+
text = this.getText() and
778+
end = start + match.length() and
779+
inner = match.substring(1, match.length() - 1)
780+
|
781+
match = text.regexpFind("\\{[0-9]+\\}", _, start) and
780782
lower = inner and
781783
upper = lower
782784
or
783-
inner.regexpMatch("[0-9]*,[0-9]*") and
784-
exists(int commaIndex | commaIndex = inner.indexOf(",") |
785+
match = text.regexpFind("\\{[0-9]*,[0-9]*\\}", _, start) and
786+
exists(int commaIndex |
787+
commaIndex = inner.indexOf(",") and
785788
lower = inner.prefix(commaIndex) and
786789
upper = inner.suffix(commaIndex + 1)
787790
)

0 commit comments

Comments
 (0)