Skip to content

Commit 1857de1

Browse files
committed
JS: Speed up detection of jQuery marker comments
Combine two regexes into a single one. This saves up to 5s on large databases by reducing the number of separate scans of the comments table before regex matching. The combined regex is slightly more permissive than the original two, since it allows a combination of the two matched formats. A string that matches one of the original regexes will match the combined regex.
1 parent 6a1aea7 commit 1857de1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

javascript/ql/lib/semmle/javascript/dependencies/FrameworkLibraries.qll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,15 @@ private class JQuery extends FrameworkLibraryWithGenericURL {
299299
private predicate jQueryMarkerComment(Comment c, TopLevel tl, string version) {
300300
tl = c.getTopLevel() and
301301
exists(string txt | txt = c.getText() |
302-
// more recent versions use this format
302+
// More recent versions use this format:
303+
// "(?s).*jQuery (?:JavaScript Library )?v(" + versionRegex() + ").*",
304+
// Earlier versions used this format:
305+
// "(?s).*jQuery (" + versionRegex() + ") - New Wave Javascript.*"
306+
// For efficiency, construct a single regex that matches both,
307+
// at the cost of being slightly more permissive.
303308
version =
304-
txt.regexpCapture("(?s).*jQuery (?:JavaScript Library )?v(" + versionRegex() + ").*", 1)
305-
or
306-
// earlier versions used this format
307-
version = txt.regexpCapture("(?s).*jQuery (" + versionRegex() + ") - New Wave Javascript.*", 1)
309+
txt.regexpCapture("(?s).*jQuery (?:JavaScript Library )?v?(" + versionRegex() +
310+
")(?: - New Wave Javascript)?.*", 1)
308311
or
309312
// 1.0.0 and 1.0.1 have the same marker comment; we call them both "1.0"
310313
txt.matches("%jQuery - New Wave Javascript%") and version = "1.0"

0 commit comments

Comments
 (0)