From e0e97a0f092081764715e79dd8f2ed7c94b8c703 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 23 Oct 2012 16:53:00 -0700 Subject: [PATCH] optimize newline removal in eliminator --- tools/eliminator.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/eliminator.js b/tools/eliminator.js index 0018a44e6..e6c9f8080 100644 --- a/tools/eliminator.js +++ b/tools/eliminator.js @@ -507,11 +507,13 @@ function main() { for (var i = 0; i < ast1.length; i++) { var node = ast1[i]; - // Parse && recompile again, to remove unneeded lines XXX is this worth the parse time? - var src2 = uglify.uglify.gen_code(node, GEN_OPTIONS); - var node2 = uglify.parser.parse(src2); - - process.stdout.write(uglify.uglify.gen_code(node2, GEN_OPTIONS)); + var js = uglify.uglify.gen_code(node, GEN_OPTIONS), old; + // remove unneeded newlines+spaces + do { + old = js; + js = js.replace(/\n *\n/g, '\n'); + } while (js != old); + process.stdout.write(js); process.stdout.write('\n'); } process.stdout.write(generatedFunctionsLine + '\n');