Last active
December 21, 2015 06:19
-
-
Save pvdz/6263206 to your computer and use it in GitHub Desktop.
This is the ignore-whitespace of https://github.com/qfox/zeparser2/commit/86313d79ffafc21a3a71a4b8f1505d3269e0735b
This diff is causing my parser to slow down by about 100% (in Chrome, at least) ... Crazy.
This file contains hidden or 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
| diff --git a/src/par.js b/src/par.js | |
| index 2a3507e..bef9db8 100644 | |
| --- a/src/par.js | |
| +++ b/src/par.js | |
| @@ -1,4 +1,7 @@ | |
| -if (typeof Tok === 'undefined') var Tok = require(__dirname+'/tok.js').Tok; | |
| + | |
| + | |
| +(function(exports){ | |
| + var Tok = exports.Tok || require(__dirname+'/tok.js').Tok; | |
| // indices match slots of the start-regexes (where applicable) | |
| // this order is determined by regex/parser rules so they are fixed | |
| @@ -20,14 +23,13 @@ var ASI = 15; | |
| var ERROR = 16; | |
| var WHITE = 18; // WHITE_SPACE, LINETERMINATOR COMMENT_SINGLE COMMENT_MULTI | |
| -var Par = function(input){ | |
| + var Par = exports.Par = function(input){ | |
| this.tok = new Tok(input); | |
| }; | |
| Par.prototype = { | |
| run: function(){ | |
| // prepare | |
| -// if (this.tok.input === '500') debugger | |
| this.tok.nextExpr(); | |
| // go! | |
| this.parseStatements(false, false, false, []); | |
| @@ -1059,4 +1061,4 @@ Par.prototype = { | |
| }, | |
| }; | |
| -if (typeof exports === 'object') exports.Par = Par; | |
| +})(typeof exports === 'object' ? exports : window); | |
| diff --git a/src/tok.js b/src/tok.js | |
| index 6f5becc..e7e42ce 100644 | |
| --- a/src/tok.js | |
| +++ b/src/tok.js | |
| @@ -1,3 +1,5 @@ | |
| +(function(exports){ | |
| + | |
| // indices match slots of the start-regexes (where applicable) | |
| // this order is determined by regex/parser rules so they are fixed | |
| var WHITE_SPACE = 1; | |
| @@ -28,7 +30,7 @@ var WHITE = 18; // WHITE_SPACE, LINETERMINATOR COMMENT_SINGLE COMMENT_MULTI | |
| * @constructor | |
| * @param {string} input | |
| */ | |
| -var Tok = function(input){ | |
| + var Tok = exports.Tok = function(input){ | |
| this.tokens = []; | |
| this.input = (input||''); | |
| @@ -54,6 +56,7 @@ var Tok = function(input){ | |
| }; | |
| // reverse lookup (only used for error messages..) | |
| + | |
| Tok[WHITE_SPACE] = 'whitespace'; | |
| Tok[LINETERMINATOR] = 'lineterminator'; | |
| Tok[COMMENT_SINGLE] = 'comment_single'; | |
| @@ -173,7 +176,6 @@ Tok.prototype = { | |
| * possibly expecting a division (so not | |
| * a regex). | |
| * | |
| - * @param {number} type | |
| * @return {boolean} | |
| */ | |
| nextPuncIfValue: function(){ | |
| @@ -824,4 +826,4 @@ Tok.prototype = { | |
| }, | |
| }; | |
| -if (typeof exports === 'object') exports.Tok = Tok; | |
| +})(typeof exports === 'object' ? exports : window); | |
| (END) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(It was due to using an object literal as prototype object, which is bugged in chrome and deoptimizes)