diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-10-16 18:04:36 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-16 18:04:36 -0700 |
commit | 128137d92d7144607a56c736514c148ca4ce7029 (patch) | |
tree | 01cdec043e9f5eded65974bc29a20a8b4dc53ec8 | |
parent | 39cb16d507c3711de89f0997c08720fbdca02879 (diff) |
emit only tokens from tokenize, avoid allocating an object to wrap them
-rw-r--r-- | src/analyzer.js | 2 | ||||
-rw-r--r-- | src/intertyper.js | 22 | ||||
-rw-r--r-- | src/parseTools.js | 2 |
3 files changed, 13 insertions, 13 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 95fbccc7..b5ec80c6 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -1007,7 +1007,7 @@ function analyzer(data, sidePass) { internal = internal.substr(2, internal.length-4); Types.types[type] = { name_: type, - fields: splitTokenList(tokenize(internal).tokens).map(function(segment) { + fields: splitTokenList(tokenize(internal)).map(function(segment) { return segment[0].text; }), packed: packed, diff --git a/src/intertyper.js b/src/intertyper.js index bfeed625..41fba007 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -11,7 +11,7 @@ var tokenCache = {}; //var tokenCacheMisses = {}; // Line tokenizer -function tokenize(text, lineNum, indent) { +function tokenize(text) { var tokens = []; var quotes = 0; var lastToken = null; @@ -49,7 +49,7 @@ function tokenize(text, lineNum, indent) { text: text }; if (text[0] in enclosers) { - token.tokens = tokenize(text.substr(1, text.length-2)).tokens; + token.tokens = tokenize(text.substr(1, text.length-2)); token.type = text[0]; } // merge function definitions together @@ -73,7 +73,6 @@ function tokenize(text, lineNum, indent) { var i = -1; var start = 0; var segment, letter, last; - indent = indent || lineText.search(/[^ ]/); if (lineText[0] === '}') { tokens.push(tokenCache['}']); // end of function and landingpads have an unmatched { } @@ -136,12 +135,7 @@ function tokenize(text, lineNum, indent) { if (last === '{') { tokens.push(tokenCache['{']); // beginning of function and landingpads have an unmatched { } - var newItem = { - tokens: tokens, - indent: indent, - lineNum: lineNum || 0 - }; - return newItem; + return tokens; } // Handy sets @@ -246,7 +240,7 @@ function intertyper(lines, sidePass, baseLineNums) { if (mainPass && /^}.*/.test(line)) { inFunction = false; if (mainPass) { - var func = funcHeaderHandler(tokenize(currFunctionLines[0], currFunctionLineNum)); + var func = funcHeaderHandler({ tokens: tokenize(currFunctionLines[0], currFunctionLineNum) }); if (SKIP_STACK_IN_SMALL && /emscripten_autodebug/.exec(func.ident)) { warnOnce('Disabling SKIP_STACK_IN_SMALL because we are apparently processing autodebugger data'); @@ -1132,7 +1126,13 @@ function intertyper(lines, sidePass, baseLineNums) { } } - var t = tokenize(line.lineText, line.lineNum, indent); + var tokens = tokenize(line.lineText); + var t = { + tokens: tokens, + indent: indent || line.lineText.search(/[^ ]/), + lineNum: line.lineNum + }; + if (assignTo) { t.assignTo = t.tokens[0].text !== 'type' ? toNiceIdent(assignTo) : assignTo; } diff --git a/src/parseTools.js b/src/parseTools.js index bc151843..36b75018 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -280,7 +280,7 @@ function isFunctionType(type, out) { i--; } assert(argText); - return isFunctionDef({ text: argText, tokens: tokenize(argText.substr(1, argText.length-2)).tokens }, out); + return isFunctionDef({ text: argText, tokens: tokenize(argText.substr(1, argText.length-2)) }, out); } function getReturnType(type) { |