r110121 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110120‎ | r110121 | r110122 >
Date:13:32, 27 January 2012
Author:gwicke
Status:deferred
Tags:visualeditor 
Comment:
A few minor tweaks to reduce memory usage
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js
@@ -23,6 +23,7 @@
2424 jsDiff = require('diff'),
2525 colors = require('colors'),
2626 util = require( 'util' ),
 27+ jsdom = require( 'jsdom' ),
2728 HTML5 = require('html5').HTML5, //TODO is this fixup for tests only, or part of real parsing...
2829 PEG = require('pegjs'),
2930 // Handle options/arguments with optimist module
@@ -165,14 +166,16 @@
166167
167168 try {
168169 this.testParser = PEG.buildParser(fs.readFileSync('parserTests.pegjs', 'utf8'));
169 - } catch (e) {
170 - console.log(e);
 170+ } catch (e2) {
 171+ console.log(e2);
171172 }
172173
173174 this.cases = this.getTests();
174175
175176 this.articles = {};
176177
 178+ //this.htmlwindow = jsdom.jsdom(null, null, {parser: HTML5}).createWindow();
 179+ //this.htmlparser = new HTML5.Parser({document: this.htmlwindow.document});
177180 this.htmlparser = new HTML5.Parser();
178181
179182 // Test statistics
@@ -207,7 +210,7 @@
208211 testFile = fs.readFileSync( this.testFileName2, 'utf8' );
209212 fileDependencies.push( this.testFileName2 );
210213 }
211 - catch(e) { console.log(e); }
 214+ catch( e3 ) { console.log( e3 ); }
212215 }
213216 }
214217 if( !this.argv.cache ) {
@@ -232,7 +235,7 @@
233236 cache_content = fs.readFileSync( this.cache_file, 'utf8' );
234237 // Fetch previous digest
235238 cache_file_digest = cache_content.match( /^CACHE: (\w+)\n/ )[1];
236 - } catch(e) {
 239+ } catch( e4 ) {
237240 // cache file does not exist
238241 }
239242
@@ -288,8 +291,7 @@
289292 source = source.replace(/[\r\n]/g, '');
290293 try {
291294 this.htmlparser.parse('<body>' + source + '</body>');
292 - return this.htmlparser.document
293 - .getElementsByTagName('body')[0]
 295+ return this.htmlparser.document.getElementsByTagName('body')[0]
294296 .innerHTML
295297 // a few things we ignore for now..
296298 .replace(/\/wiki\/Main_Page/g, 'Main Page')
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js
@@ -56,22 +56,20 @@
5757 this.processToken({type: 'TAG', name: 'body'});
5858 };
5959
 60+FauxHTML5.TreeBuilder.prototype._att = function (maybeAttribs) {
 61+ var atts = [];
 62+ if ( maybeAttribs && $.isArray( maybeAttribs ) ) {
 63+ for(var i = 0, length = maybeAttribs.length; i < length; i++) {
 64+ var att = maybeAttribs[i];
 65+ atts.push({nodeName: att[0], nodeValue: att[1]});
 66+ }
 67+ }
 68+ return atts;
 69+};
6070
6171 // Adapt the token format to internal HTML tree builder format, call the actual
6272 // html tree builder by emitting the token.
6373 FauxHTML5.TreeBuilder.prototype.processToken = function (token) {
64 - var att = function (maybeAttribs) {
65 - if ( $.isArray( maybeAttribs ) ) {
66 - var atts = [];
67 - for(var i = 0, length = maybeAttribs.length; i < length; i++) {
68 - var att = maybeAttribs[i];
69 - atts.push({nodeName: att[0], nodeValue: att[1]});
70 - }
71 - return atts;
72 - } else {
73 - return [];
74 - }
75 - };
7674
7775 switch (token.type) {
7876 case "TEXT":
@@ -80,23 +78,23 @@
8179 case "TAG":
8280 this.emit('token', {type: 'StartTag',
8381 name: token.name,
84 - data: att(token.attribs)});
 82+ data: this._att(token.attribs)});
8583 break;
8684 case "ENDTAG":
8785 this.emit('token', {type: 'EndTag',
8886 name: token.name,
89 - data: att(token.attribs)});
 87+ data: this._att(token.attribs)});
9088 break;
9189 case "SELFCLOSINGTAG":
9290 this.emit('token', {type: 'StartTag',
9391 name: token.name,
94 - data: att(token.attribs)});
 92+ data: this._att(token.attribs)});
9593 if ( HTML5.VOID_ELEMENTS.indexOf( token.name.toLowerCase() ) < 0 ) {
9694 // VOID_ELEMENTS are automagically treated as self-closing by
9795 // the tree builder
9896 this.emit('token', {type: 'EndTag',
9997 name: token.name,
100 - data: att(token.attribs)});
 98+ data: this._att(token.attribs)});
10199 }
102100 break;
103101 case "COMMENT":
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -263,6 +263,7 @@
264264 // be part of a stream, only when tokenizing complete
265265 // texts)
266266 //console.log( pp( flatten ( e ) ) );
 267+ cache = {};
267268 __parseArgs[2]( [ { type: 'END' } ] );
268269 return []; //flatten(e);
269270 }
@@ -300,8 +301,8 @@
301302 */
302303
303304 urltext = ( t:[^'<~[{\n\rfghimnstw|!:\]} &=]+ { return t.join(''); }
 305+ / & url_chars urllink
304306 / htmlentity
305 - / urllink
306307 // Convert trailing space into &nbsp;
307308 // XXX: This should be moved to a serializer
308309 / ' ' & ':' { return "\u00a0"; }
@@ -411,6 +412,7 @@
412413 //console.log('about to emit' + pp(self));
413414 //console.log( '__parseArgs call: ' + pp( b ));
414415 __parseArgs[2]( flatten( b ) );
 416+
415417 //return [];
416418 return true;
417419 }
@@ -653,6 +655,9 @@
654656
655657 /* Defaul URL protocols in MediaWiki (see DefaultSettings). Normally these can
656658 * be configured dynamically. */
 659+
 660+url_chars = [/fghimnstw]
 661+
657662 url_protocol
658663 = '//' // for protocol-relative URLs
659664 / 'ftp://'
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
@@ -28,6 +28,7 @@
2929 if ( !this.parser ) {
3030 // Only create a single parser, as parse() is a static method.
3131 var parserSource = PEG.buildParser(this.src).toSource();
 32+ //console.log( parserSource );
3233 parserSource = parserSource.replace( 'parse: function(input, startRule) {',
3334 'parse: function(input, startRule) { var __parseArgs = arguments;' );
3435 //console.log( parserSource );
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
@@ -233,7 +233,7 @@
234234
235235 ParserPipeline.prototype.cachePipeline = function ( inputType, pipelinePart, pipe ) {
236236 var cache = this.pipelineCache[inputType][pipelinePart];
237 - if ( cache && cache.length < 50 ) {
 237+ if ( cache && cache.length < 5 ) {
238238 cache.push( pipe );
239239 }
240240 };

Status & tagging log