jenkins-bot has submitted this change and it was merged. Change subject: Don't require several modules on each parse call ......................................................................
Don't require several modules on each parse call Change-Id: I19ee11853e96eafc4b0ea25112570915090de6be --- M lib/mediawiki.tokenizer.peg.js M lib/pegTokenizer.pegjs.txt 2 files changed, 41 insertions(+), 12 deletions(-) Approvals: Subramanya Sastry: Looks good to me, approved Cscott: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/lib/mediawiki.tokenizer.peg.js b/lib/mediawiki.tokenizer.peg.js index 1c47799..361556b 100644 --- a/lib/mediawiki.tokenizer.peg.js +++ b/lib/mediawiki.tokenizer.peg.js @@ -16,12 +16,28 @@ events = require('events'), util = require('util'); +/** + * Includes passed to the tokenizer, so that it does not need to require those + * on each call. They are available as pegArgs.pegIncludes, and are unpacked + * in the head of pegTokenizer.pegjs.txt. + */ +var pegIncludes = { + Util: require('./mediawiki.Util.js').Util, + defines: require('./mediawiki.parser.defines.js'), + // defined below to satisfy JSHint + PegTokenizer: null +}; + + + function PegTokenizer( env, options ) { events.EventEmitter.call(this); this.env = env; this.options = options || {}; this.offsets = {}; } + +pegIncludes.PegTokenizer = PegTokenizer; // Inherit from EventEmitter util.inherits(PegTokenizer, events.EventEmitter); @@ -115,7 +131,13 @@ // Kick it off! var srcOffset = this.offsets.startOffset || 0; - var args = { cb: chunkCB, pegTokenizer: this, srcOffset: srcOffset, env: this.env }; + var args = { + cb: chunkCB, + pegTokenizer: this, + srcOffset: srcOffset, + env: this.env, + pegIncludes: pegIncludes + }; if (fullParse) { if ( ! this.env.conf.parsoid.debug ) { try { @@ -135,7 +157,13 @@ PegTokenizer.prototype.tokenizeAsync = function( text, srcOffset, cb ) { var ret, pegTokenizer = this, - args = { cb: cb, pegTokenizer: this, srcOffset: srcOffset, env: this.env }; + args = { + cb: cb, + pegTokenizer: this, + srcOffset: srcOffset, + env: this.env, + pegIncludes: pegIncludes + }; if ( ! this.env.conf.parsoid.debug ) { try { @@ -183,7 +211,8 @@ cb: function(r) { toks = toks.concat(r); }, pegTokenizer: this, srcOffset: this.offsets.startOffset || 0, - env: this.env + env: this.env, + pegIncludes: pegIncludes }; } var retToks = this.tokenizer.tokenize(text, production, args); @@ -205,7 +234,7 @@ * Tokenize a URL */ PegTokenizer.prototype.tokenizeURL = function( text ) { - var args = { pegTokenizer: this, env: this.env }; + var args = { pegTokenizer: this, env: this.env, pegIncludes: pegIncludes }; return this.tokenize(text, "url", args); }; @@ -213,7 +242,7 @@ * Tokenize table cell attributes */ PegTokenizer.prototype.tokenizeTableCellAttributes = function( text ) { - var args = { pegTokenizer: this, env: this.env }; + var args = { pegTokenizer: this, env: this.env, pegIncludes: pegIncludes }; return this.tokenize(text, "single_cell_table_args", args); }; diff --git a/lib/pegTokenizer.pegjs.txt b/lib/pegTokenizer.pegjs.txt index 74b6998..6598c02 100644 --- a/lib/pegTokenizer.pegjs.txt +++ b/lib/pegTokenizer.pegjs.txt @@ -33,13 +33,13 @@ // return es; //}; - require('./core-upgrade'); - var Util = require('./mediawiki.Util.js').Util; - var PegTokenizer = require('./mediawiki.tokenizer.peg.js').PegTokenizer; + var pegIncludes = pegArgs.pegIncludes, + Util = pegIncludes.Util, + PegTokenizer = pegIncludes.PegTokenizer, + defines = pegIncludes.defines; - // import defines and define some constructor shortcuts - var defines = require('./mediawiki.parser.defines.js'), - KV = defines.KV, + // define some constructor shortcuts + var KV = defines.KV, TagTk = defines.TagTk, SelfclosingTagTk = defines.SelfclosingTagTk, EndTagTk = defines.EndTagTk, @@ -399,7 +399,7 @@ * current expression can return an empty list (true). */ var emitChunk = function (tokens) { - var env = pegArgs.pegTokenizer.env; + var env = pegArgs.env; // shift tsr of all tokens by offset Util.shiftTokenTSR(tokens, pegArgs.srcOffset); env.log("trace/peg", pegArgs.pegTokenizer.pipelineId, "----> ", tokens); -- To view, visit https://gerrit.wikimedia.org/r/130275 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I19ee11853e96eafc4b0ea25112570915090de6be Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: GWicke <gwi...@wikimedia.org> Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org> Gerrit-Reviewer: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: GWicke <gwi...@wikimedia.org> Gerrit-Reviewer: Marcoil <marc...@wikimedia.org> Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits