diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-02-26 05:58:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-26 05:58:26 +0800 |
commit | 13be50a4a9e34d65fef834625f44545e849fed02 (patch) | |
tree | 2b4be9da6a6d7ded94d97b14b78274293865f76b /lib/ast.js | |
parent | 16cd5d57a5cf7f5750104df0e5af246708fd493f (diff) | |
download | tracifyjs-13be50a4a9e34d65fef834625f44545e849fed02.tar.gz tracifyjs-13be50a4a9e34d65fef834625f44545e849fed02.zip |
faster tree transversal (#1462)
- convert `[].forEach()` to for-loops
Diffstat (limited to 'lib/ast.js')
-rw-r--r-- | lib/ast.js | 46 |
1 files changed, 26 insertions, 20 deletions
@@ -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); + } }); } }); |