[Pkg-javascript-commits] [node-detective] 94/119: improve traverse perf by using for-loops

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:44:38 UTC 2017


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

rouca pushed a commit to branch master
in repository node-detective.

commit 3a77e45ed0c8a301327d7545e8b0d7d069cf2978
Author: Andres Suarez <zertosh at gmail.com>
Date:   Sat May 23 20:56:20 2015 -0400

    improve traverse perf by using for-loops
---
 index.js | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/index.js b/index.js
index ea38e27..dbca43e 100644
--- a/index.js
+++ b/index.js
@@ -20,21 +20,21 @@ function parse (src, opts) {
 
 var traverse = function (node, cb) {
     if (Array.isArray(node)) {
-        node.forEach(function (x) {
-            if(x != null) {
-                x.parent = node;
-                traverse(x, cb);
+        for (var i = 0; i < node.length; i++) {
+            if (node[i] != null) {
+                node[i].parent = node;
+                traverse(node[i], cb);
             }
-        });
+        }
     }
     else if (node && typeof node === 'object') {
         cb(node);
-
-        Object.keys(node).forEach(function (key) {
-            if (key === 'parent' || !node[key]) return;
+        for (var key in node) {
+            if (!node.hasOwnProperty(key)) continue;
+            if (key === 'parent' || !node[key]) continue;
             node[key].parent = node;
             traverse(node[key], cb);
-        });
+        }
     }
 };
 

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



More information about the Pkg-javascript-commits mailing list