[Pkg-javascript-commits] [uglifyjs] 45/228: faster tree transversal (#1462)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:15 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit 13be50a4a9e34d65fef834625f44545e849fed02
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun Feb 26 05:58:26 2017 +0800

    faster tree transversal (#1462)
    
    - convert `[].forEach()` to for-loops
---
 lib/ast.js      | 46 ++++++++++++++++++++++++++--------------------
 lib/compress.js |  2 +-
 2 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/lib/ast.js b/lib/ast.js
index 61643ae..f3df78f 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -145,12 +145,13 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
 }, AST_Statement);
 
 function walk_body(node, visitor) {
-    if (node.body instanceof AST_Statement) {
-        node.body._walk(visitor);
+    var body = node.body;
+    if (body instanceof AST_Statement) {
+        body._walk(visitor);
+    }
+    else for (var i = 0, len = body.length; i < len; i++) {
+        body[i]._walk(visitor);
     }
-    else node.body.forEach(function(stat){
-        stat._walk(visitor);
-    });
 };
 
 var AST_Block = DEFNODE("Block", "body", {
@@ -371,9 +372,10 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
     _walk: function(visitor) {
         return visitor._visit(this, function(){
             if (this.name) this.name._walk(visitor);
-            this.argnames.forEach(function(arg){
-                arg._walk(visitor);
-            });
+            var argnames = this.argnames;
+            for (var i = 0, len = argnames.length; i < len; i++) {
+                argnames[i]._walk(visitor);
+            }
             walk_body(this, visitor);
         });
     }
@@ -533,9 +535,10 @@ var AST_Definitions = DEFNODE("Definitions", "definitions", {
     },
     _walk: function(visitor) {
         return visitor._visit(this, function(){
-            this.definitions.forEach(function(def){
-                def._walk(visitor);
-            });
+            var definitions = this.definitions;
+            for (var i = 0, len = definitions.length; i < len; i++) {
+                definitions[i]._walk(visitor);
+            }
         });
     }
 }, AST_Statement);
@@ -573,9 +576,10 @@ var AST_Call = DEFNODE("Call", "expression args", {
     _walk: function(visitor) {
         return visitor._visit(this, function(){
             this.expression._walk(visitor);
-            this.args.forEach(function(arg){
-                arg._walk(visitor);
-            });
+            var args = this.args;
+            for (var i = 0, len = args.length; i < len; i++) {
+                args[i]._walk(visitor);
+            }
         });
     }
 });
@@ -742,9 +746,10 @@ var AST_Array = DEFNODE("Array", "elements", {
     },
     _walk: function(visitor) {
         return visitor._visit(this, function(){
-            this.elements.forEach(function(el){
-                el._walk(visitor);
-            });
+            var elements = this.elements;
+            for (var i = 0, len = elements.length; i < len; i++) {
+                elements[i]._walk(visitor);
+            }
         });
     }
 });
@@ -756,9 +761,10 @@ var AST_Object = DEFNODE("Object", "properties", {
     },
     _walk: function(visitor) {
         return visitor._visit(this, function(){
-            this.properties.forEach(function(prop){
-                prop._walk(visitor);
-            });
+            var properties = this.properties;
+            for (var i = 0, len = properties.length; i < len; i++) {
+                properties[i]._walk(visitor);
+            }
         });
     }
 });
diff --git a/lib/compress.js b/lib/compress.js
index ccd6e23..5383311 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1911,7 +1911,7 @@ merge(Compressor.prototype, {
         // returned if nothing changed.
         function trim(nodes, compressor, first_in_statement) {
             var ret = [], changed = false;
-            for (var i = 0, ii = nodes.length; i < ii; i++) {
+            for (var i = 0, len = nodes.length; i < len; i++) {
                 var node = nodes[i].drop_side_effect_free(compressor, first_in_statement);
                 changed |= node !== nodes[i];
                 if (node) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list