From eca96f1905045b93a6d0ee9ea26c5ec16ee24353 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Fri, 16 Jun 2017 15:01:00 +0800 Subject: [PATCH] in-place `join_vars` --- lib/compress.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 4f92f289..3a361521 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -679,7 +679,7 @@ merge(Compressor.prototype, { statements = sequencesize(statements, compressor); } if (compressor.option("join_vars")) { - statements = join_consecutive_vars(statements, compressor); + join_consecutive_vars(statements, compressor); } if (compressor.option("collapse_vars")) { collapse(statements, compressor); @@ -1173,8 +1173,9 @@ merge(Compressor.prototype, { }; function join_consecutive_vars(statements, compressor) { - var prev = null; - return statements.reduce(function(a, stat){ + for (var i = 0, j = -1, len = statements.length; i < len; i++) { + var stat = statements[i]; + var prev = statements[j]; if (stat instanceof AST_Definitions && prev && prev.TYPE == stat.TYPE) { prev.definitions = prev.definitions.concat(stat.definitions); CHANGED = true; @@ -1183,21 +1184,18 @@ merge(Compressor.prototype, { && prev instanceof AST_Var && (!stat.init || stat.init.TYPE == prev.TYPE)) { CHANGED = true; - a.pop(); if (stat.init) { stat.init.definitions = prev.definitions.concat(stat.init.definitions); } else { stat.init = prev; } - a.push(stat); - prev = stat; + statements[j] = stat; } else { - prev = stat; - a.push(stat); + statements[++j] = stat; } - return a; - }, []); + } + statements.length = j + 1; }; };