diff options
author | alon@honor <none@none> | 2010-10-16 15:33:19 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-10-16 15:33:19 -0700 |
commit | 373e75c2151229ae4b6caaae77eb9d49da72e2c2 (patch) | |
tree | 6297cdad2fa5c916b25768cdef99807e44f3ca72 /src/jsifier.js | |
parent | 6fa5f7160c816fc982432dc5f990a1da14d09175 (diff) |
optimize out unneeded loops in |multiple| blocks
Diffstat (limited to 'src/jsifier.js')
-rw-r--r-- | src/jsifier.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index b6c36db0..15e66669 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -343,17 +343,23 @@ function JSify(data) { ret += indent + '}\n'; } else if (block.type == 'multiple') { var first = true; - ret += indent + ((block.entry in usedLabels) ? '' : (block.entry+':')) + ' do { \n'; + var multipleIdent = ''; + if (!block.loopless) { + ret += indent + ((block.entry in usedLabels) ? '' : (block.entry+':')) + ' do { \n'; + multipleIdent = ' '; + } block.entryLabels.forEach(function(entryLabel) { - ret += indent + (first ? '' : ' else ') + ' if (__label__ == ' + getLabelId(entryLabel.ident) + ') {\n'; - ret += walkBlock(entryLabel.block, indent + ' '); - ret += indent + ' }\n'; + ret += indent + (first ? '' : 'else ') + multipleIdent + 'if (__label__ == ' + getLabelId(entryLabel.ident) + ') {\n'; + ret += walkBlock(entryLabel.block, indent + ' ' + multipleIdent); + ret += indent + multipleIdent + '}\n'; first = false; }); if (GUARD_LABELS) { - ret += indent + ' else { throw "Bad multiple branching: " + __label__ + " : " + (new Error().stack); }\n'; + ret += indent + multipleIdent + 'else { throw "Bad multiple branching: " + __label__ + " : " + (new Error().stack); }\n'; + } + if (!block.loopless) { + ret += indent + '} while(0);\n'; } - ret += indent + '} while(0);\n'; } else { throw "Walked into an invalid block type: " + block.type; } |