Skip to content

Commit

Permalink
Improved regex performance of C-like strings and JS regexps
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Jun 20, 2015
1 parent a88aae8 commit 476cbf4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/prism-clike.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Prism.languages.clike = {
lookbehind: true
}
],
'string': /("|')(\\\n|\\?.)*?\1/,
'string': /("|')(\\[\s\S]|(?!\1)[^\\])*\1/,
'class-name': {
pattern: /((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
lookbehind: true,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-clike.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {

Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
lookbehind: true
}
});
Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ Prism.languages.clike = {
lookbehind: true
}
],
'string': /("|')(\\\n|\\?.)*?\1/,
'string': /("|')(\\[\s\S]|(?!\1)[^\\])*\1/,
'class-name': {
pattern: /((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
lookbehind: true,
Expand Down Expand Up @@ -583,7 +583,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {

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

0 comments on commit 476cbf4

Please sign in to comment.