Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit c2dfea6

Browse files
sped up parsing for large files by replacing tokenizing loop with a single regular expression match.
1 parent cabfab6 commit c2dfea6

File tree

8 files changed

+764
-548
lines changed

8 files changed

+764
-548
lines changed

src/lang-css.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ PR.registerLangHandler(
4242
/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/, null],
4343
[PR.PR_STRING,
4444
/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/, null],
45-
[PR.PR_STRING, /^\([^\)\"\']*\)/, /\burl/i],
45+
['lang-css-str', /^url\(([^\)\"\']*)\)/i],
4646
[PR.PR_KEYWORD,
4747
/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,
4848
null],
4949
// A property name -- an identifier followed by a colon.
50-
[PR.PR_KEYWORD, /^-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*(?=\s*:)/i],
50+
['lang-css-kw', /^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],
5151
// A C style block comment. The <comment> production.
5252
[PR.PR_COMMENT, /^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],
5353
// Escaping text spans
@@ -63,3 +63,16 @@ PR.registerLangHandler(
6363
[PR.PR_PUNCTUATION, /^[^\s\w\'\"]+/]
6464
]),
6565
['css']);
66+
PR.registerLangHandler(
67+
PR.createSimpleLexer([],
68+
[
69+
[PR.PR_KEYWORD,
70+
/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]
71+
]),
72+
['css-kw']);
73+
PR.registerLangHandler(
74+
PR.createSimpleLexer([],
75+
[
76+
[PR.PR_STRING, /^[^\)\"\']+/]
77+
]),
78+
['css-str']);

src/lang-vb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ PR.registerLangHandler(
3737
[PR.PR_PLAIN, /^[\t\n\r \xA0\u2028\u2029]+/, null, '\t\n\r \xA0\u2028\u2029'],
3838
// A double quoted string with quotes escaped by doubling them.
3939
// A single character can be suffixed with C.
40-
[PR.PR_STRING, /^(?:[\"\u201C\u201D](?:[^\"\u201C\u201D]|[\"\u201C\u201D]{2})(?:[\"\u201C\u201D][cC]|$)|[\"\u201C\u201D](?:[^\"\u201C\u201D]|[\"\u201C\u201D]{2})*(?:[\"\u201C\u201D]|$))/, null,
40+
[PR.PR_STRING, /^(?:[\"\u201C\u201D](?:[^\"\u201C\u201D]|[\"\u201C\u201D]{2})(?:[\"\u201C\u201D]c|$)|[\"\u201C\u201D](?:[^\"\u201C\u201D]|[\"\u201C\u201D]{2})*(?:[\"\u201C\u201D]|$))/i, null,
4141
'"\u201C\u201D'],
4242
// A comment starts with a single quote and runs until the end of the
4343
// line.

src/lang-wiki.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ PR.registerLangHandler(
2626
PR.createSimpleLexer(
2727
[
2828
// Whitespace
29-
[PR.PR_PLAIN, /^[\t\n\r \xA0a-gi-z0-9]+/, null,
30-
'\t\n\r \xA0abcdefgijklmnopqrstuvwxyz0123456789'],
29+
[PR.PR_PLAIN, /^[\t \xA0a-gi-z0-9]+/, null,
30+
'\t \xA0abcdefgijklmnopqrstuvwxyz0123456789'],
3131
// Wiki formatting
3232
[PR.PR_PUNCTUATION, /^[=*~\^\[\]]+/, null, '=*~^[]']
3333
],
3434
[
3535
// Meta-info like #summary, #labels, etc.
36-
[PR.PR_KEYWORD, /^#[a-z]+\b/, /(?:^|[\r\n])$/],
36+
['lang-wiki.meta', /(?:^^|[\r\n])(#[a-z]+)\b/],
3737
// A WikiWord
3838
[PR.PR_LITERAL, /^(?:[A-Z][a-z][a-z0-9]+[A-Z][a-z][a-zA-Z0-9]+)\b/
3939
],
@@ -44,6 +44,10 @@ PR.registerLangHandler(
4444
// An inline URL.
4545
[PR.PR_STRING,
4646
/^https?:\/\/[^\/?#\s]*(?:\/[^?#\s]*)?(?:\?[^#\s]*)?(?:#\S*)?/i],
47-
[PR.PR_PLAIN, /^[\s\S][^#=*~^A-Zh\{`\[]+/]
47+
[PR.PR_PLAIN, /^[\s\S][^#=*~^A-Zh\{`\[\r\n]+/]
4848
]),
4949
['wiki']);
50+
51+
PR.registerLangHandler(
52+
PR.createSimpleLexer([[PR.PR_KEYWORD, /^#[a-z]+/i, null, '#']], []),
53+
['wiki.meta']);

0 commit comments

Comments
 (0)