r112030 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112029‎ | r112030 | r112031 >
Date:17:57, 21 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Fix the bug in the inline_breaks replacement, and write another switch-based
version, which is slightly faster and shorter. Performance is improved by
about 5% for parserTests.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -415,13 +415,24 @@
416416 *
417417 * XXX: Repeated testing of flags is not terribly efficient.
418418 */
419 -inline_breaks
 419+
 420+inline_breaks_ =
 421+ & [=|!}:\r\n\]<]
 422+ & { cacheKey = ''; ilbpos = pos; return true; }
 423+ res:inline_breaks_o
 424+{
 425+ console.warn( 'ilbo res: ' + JSON.stringify( [ res, input.substr( ilbpos, 4 ) ] ) );
 426+ return res;
 427+}
 428+
 429+
 430+inline_breaks_o
420431 = & [=|!}:\r\n\]<] // don't check further if char cannot match
421432 res:(
422433 & { // Important hack: disable caching for this production, as the default
423434 // cache key does not take into account flag states!
424435 cacheKey = '';
425 - console.warn('ilb: ' + input.substr(pos, 5) );
 436+ //console.warn('ilb: ' + input.substr(pos, 5) );
426437 return true;
427438 }
428439
@@ -453,16 +464,14 @@
454465 }
455466 ) { return res }
456467
457 -inline_breaks_experiment
 468+inline_breaks
458469 = & [=|!}:\r\n\]<]
459470 & { // Important hack: disable caching for this production, as the default
460471 // cache key does not take into account flag states!
461472 cacheKey = '';
462473 //console.warn('ilbf: ' + input.substr(pos, 5) );
463 - return true;
 474+ return null !== __parseArgs[3].inline_breaks( input, pos, syntaxFlags )
464475 }
465 - .
466 - { return __parseArgs[3].inline_breaks( input, pos - 1, syntaxFlags ) && true || null ; }
467476
468477 inline
469478 = c:(urltext / (! inline_breaks (inline_element / . )))+ {
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
@@ -101,14 +101,13 @@
102102 },
103103 "\r": function ( input, pos, syntaxFlags ) {
104104 return syntaxFlags.table &&
105 - input[pos + 1] !== '!' &&
106 - input[pos + 1] !== '|' ||
 105+ input.substr(pos, 4).match(/\r\n?[!|]/) !== null ||
107106 null;
108107 },
109108 "\n": function ( input, pos, syntaxFlags ) {
110109 return syntaxFlags.table &&
111 - input[pos + 1] !== '!' &&
112 - input[pos + 1] !== '|' ||
 110+ input[pos + 1] === '!' ||
 111+ input[pos + 1] === '|' ||
113112 null;
114113 },
115114 "]": function ( input, pos, syntaxFlags ) {
@@ -121,12 +120,56 @@
122121 }
123122 };
124123
 124+PegTokenizer.prototype.inline_breaks_ = function (input, pos, syntaxFlags ) {
 125+ return this.breakMap[ input[pos] ]( input, pos, syntaxFlags);
 126+ //console.warn( 'ilbn res: ' + JSON.stringify( [ res, input.substr( pos, 4 ) ] ) );
 127+ //return res;
 128+};
 129+
125130 PegTokenizer.prototype.inline_breaks = function (input, pos, syntaxFlags ) {
126 - var res = this.breakMap[ input[pos] ]( input, pos, syntaxFlags);
127 - console.warn( 'ilb res: ' + JSON.stringify( [ res, input.substr( pos, 4 ) ] ) );
128 - return res;
 131+ switch( input[pos] ) {
 132+ case '=':
 133+ return syntaxFlags.equal ||
 134+ ( syntaxFlags.h &&
 135+ input.substr( pos + 1, 200)
 136+ .match(/[ \t]*[\r\n]/) !== null ) || null;
 137+ case '|':
 138+ return syntaxFlags.template ||
 139+ ( syntaxFlags.table &&
 140+ ( input[pos + 1].match(/[|}]/) !== null ||
 141+ syntaxFlags.tableCellArg
 142+ )
 143+ ) || null;
 144+ case "!":
 145+ return syntaxFlags.table && input[pos + 1] === "!" ||
 146+ null;
 147+ case "}":
 148+ return syntaxFlags.template && input[pos + 1] === "}" || null;
 149+ case ":":
 150+ return syntaxFlags.colon &&
 151+ ! syntaxFlags.extlink &&
 152+ ! syntaxFlags.linkdesc || null;
 153+ case "\r":
 154+ return syntaxFlags.table &&
 155+ input.substr(pos, 4).match(/\r\n?[!|]/) !== null ||
 156+ null;
 157+ case "\n":
 158+ return syntaxFlags.table &&
 159+ input[pos + 1] === '!' ||
 160+ input[pos + 1] === '|' ||
 161+ null;
 162+ case "]":
 163+ return syntaxFlags.extlink ||
 164+ ( syntaxFlags.linkdesc && input[pos + 1] === ']' ) ||
 165+ null;
 166+ case "<":
 167+ return syntaxFlags.pre && input.substr( pos, 6 ) === '</pre>' || null;
 168+ default:
 169+ return null;
 170+ }
129171 };
130172
 173+
131174 /*****************************************************************************
132175 * LEGACY stuff
133176 *

Status & tagging log