-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSON: Fix property and string patterns performance. Fix #1080
- Loading branch information
Showing
2 changed files
with
8 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
Prism.languages.json = { | ||
'property': /"(?:\\.|[^|"])*"(?=\s*:)/ig, | ||
'string': /"(?!:)(?:\\.|[^|"])*"(?!:)/g, | ||
'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?)\b/g, | ||
'punctuation': /[{}[\]);,]/g, | ||
'operator': /:/g, | ||
'boolean': /\b(true|false)\b/gi, | ||
'null': /\bnull\b/gi | ||
'property': /"(?:\\.|[^\\"])*"(?=\s*:)/ig, | ||
'string': /"(?!:)(?:\\.|[^\\"])*"(?!:)/g, | ||
'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?)\b/g, | ||
'punctuation': /[{}[\]);,]/g, | ||
'operator': /:/g, | ||
'boolean': /\b(true|false)\b/gi, | ||
'null': /\bnull\b/gi | ||
}; | ||
|
||
Prism.languages.jsonp = Prism.languages.json; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
0ca1353
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Golmote Because I'm terrible at Regex, I was wondering if you could shed some light as to what this change does and why it resolved the issue in the linked ticket. Thanks!
0ca1353
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mAAdhaTTah I'm not even sure I can explain. I think the choices in the alternative should try to exclude each other, which was not the case here, because of (what I assume was) a typo. The
\
could be matched by either part of the alternative, thus increasing drastically the number of possibilities. I guess that was leading to a lot of backtracking, which is just terrible for performance.0ca1353
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mAAdhaTTah I remember we encountered similar performance issues in C-like and JS strings, some time ago. And you'll notice the fix actually followed the same reasoning: 476cbf4
0ca1353
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Golmote Any chance we could get this in a release? I'd love to get it pulled into our project