Skip to content

Commit 035e747

Browse files
committed
Python: Fix slow use of regexCapture in Builtin::strValue
This is only _really_ expensive when there are a _lot_ of strings in the database, but for this case, where we're always extracting the same substring of the string, it's easier -- and faster -- to just make a substring operation directly.
1 parent 83ba8c9 commit 035e747

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

python/ql/src/semmle/python/types/Builtins.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class Builtin extends @py_cobject {
104104
) and
105105
exists(string quoted_string |
106106
quoted_string = this.getName() and
107-
result = quoted_string.regexpCapture("[bu]'([\\s\\S]*)'", 1)
107+
// Remove prefix ("b" or "u") and leading and trailing quotes (both "'").
108+
result = quoted_string.substring(2, quoted_string.length() - 1)
108109
)
109110
}
110111
}

0 commit comments

Comments
 (0)