diff options
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index c0096df4..088c4f0f 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -750,9 +750,12 @@ function simplifyExpressions(ast) { } function emitsBoolean(node) { + if (node[0] === 'num') { + return node[1] === 0 || node[1] === 1; + } if (node[0] === 'binary') return node[1] in COMPARE_OPS; if (node[0] === 'unary-prefix') return node[1] === '!'; - if (node[0] === 'conditional') return true; + if (node[0] === 'conditional') return emitsBoolean(node[2]) && emitsBoolean(node[3]); return false; } @@ -1030,6 +1033,7 @@ function hasSideEffects(node) { // this is 99% incomplete! } return false; } + case 'conditional': return hasSideEffects(node[1]) || hasSideEffects(node[2]) || hasSideEffects(node[3]); default: return true; } } @@ -3704,9 +3708,11 @@ function eliminate(ast, memSafe) { } if (firstLooperUsage >= 0) { // the looper is used, we cannot simply merge the two variables - if ((firstHelperUsage < 0 || firstHelperUsage > lastLooperUsage) && lastLooperUsage+1 < stats.length && triviallySafeToMove(stats[found], asmData)) { + if ((firstHelperUsage < 0 || firstHelperUsage > lastLooperUsage) && lastLooperUsage+1 < stats.length && triviallySafeToMove(stats[found], asmData) && + seenUses[helper] === namings[helper]) { // the helper is not used, or it is used after the last use of the looper, so they do not overlap, // and the last looper usage is not on the last line (where we could not append after it), and the + // helper is not used outside of the loop. // just move the looper definition to after the looper's last use stats.splice(lastLooperUsage+1, 0, stats[found]); stats.splice(found, 1); |