Skip to content

Commit 476cbf4

Browse files
committed
Improved regex performance of C-like strings and JS regexps
1 parent a88aae8 commit 476cbf4

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

components/prism-clike.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Prism.languages.clike = {
99
lookbehind: true
1010
}
1111
],
12-
'string': /("|')(\\\n|\\?.)*?\1/,
12+
'string': /("|')(\\[\s\S]|(?!\1)[^\\])*\1/,
1313
'class-name': {
1414
pattern: /((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
1515
lookbehind: true,

components/prism-clike.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-javascript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
66

77
Prism.languages.insertBefore('javascript', 'keyword', {
88
'regex': {
9-
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
9+
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
1010
lookbehind: true
1111
}
1212
});

components/prism-javascript.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prism.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ Prism.languages.clike = {
548548
lookbehind: true
549549
}
550550
],
551-
'string': /("|')(\\\n|\\?.)*?\1/,
551+
'string': /("|')(\\[\s\S]|(?!\1)[^\\])*\1/,
552552
'class-name': {
553553
pattern: /((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
554554
lookbehind: true,
@@ -583,7 +583,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
583583

584584
Prism.languages.insertBefore('javascript', 'keyword', {
585585
'regex': {
586-
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
586+
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
587587
lookbehind: true
588588
}
589589
});

0 commit comments

Comments
 (0)