Permalink
Browse files

spotlight: Cleanup `crawl()`. [jddalton]

  • Loading branch information...
1 parent 07d94d7 commit 631eb4c94a25ce8b0b4f0d1164d058d71b13e998 @jdalton jdalton committed Jan 13, 2012
Showing with 12 additions and 13 deletions.
  1. +6 −6 docs/README.md
  2. +6 −7 spotlight.js
View
@@ -28,7 +28,7 @@
<!-- div -->
-### <a id="spotlight" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L664" title="View in source">`spotlight`</a>
+### <a id="spotlight" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L663" title="View in source">`spotlight`</a>
*(Object)*: The primary namespace.
[&#9650;][1]
@@ -37,7 +37,7 @@
<!-- div -->
-### <a id="spotlight.debug" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L671" title="View in source">`spotlight.debug`</a>
+### <a id="spotlight.debug" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L670" title="View in source">`spotlight.debug`</a>
*(Boolean)*: A flag to indicate that methods will execute in debug mode.
[&#9650;][1]
@@ -46,7 +46,7 @@
<!-- div -->
-### <a id="spotlight.byKind" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L596" title="View in source">`spotlight.byKind(kind [, options={}])`</a>
+### <a id="spotlight.byKind" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L595" title="View in source">`spotlight.byKind(kind [, options={}])`</a>
Crawls environment objects logging all object properties whose values are of a specified constructor instance, [[Class]], or type.
[&#9650;][1]
@@ -74,7 +74,7 @@ spotlight.byKind('constructor');
<!-- div -->
-### <a id="spotlight.byName" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L617" title="View in source">`spotlight.byName(name [, options={}])`</a>
+### <a id="spotlight.byName" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L616" title="View in source">`spotlight.byName(name [, options={}])`</a>
Crawls environment objects logging all object properties of the specified name.
[&#9650;][1]
@@ -100,7 +100,7 @@ spotlight.byName('map', { 'object': jQuery, 'path': '$' });
<!-- div -->
-### <a id="spotlight.byValue" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L635" title="View in source">`spotlight.byValue(value [, options={}])`</a>
+### <a id="spotlight.byValue" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L634" title="View in source">`spotlight.byValue(value [, options={}])`</a>
Crawls environment objects logging all object properties whose values are a strict match for the specified value.
[&#9650;][1]
@@ -122,7 +122,7 @@ spotlight.byValue(0);
<!-- div -->
-### <a id="spotlight.custom" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L654" title="View in source">`spotlight.custom(callback [, options={}])`</a>
+### <a id="spotlight.custom" href="https://github.com/bestiejs/spotlight/blob/master/spotlight.js#L653" title="View in source">`spotlight.custom(callback [, options={}])`</a>
Crawls environment objects executing `callback`, passing the current `value`, `key`, and `object` as arguments, against each object encountered and logs properties for which `callback` returns true.
[&#9650;][1]
View
@@ -466,18 +466,18 @@
}
// crawl all root objects
while ((data = roots.pop())) {
- index = -1;
+ index = 0;
object = data.object;
path = data.path;
- queue = { '0': { 'object': object, 'path': path, 'pool': [object] }, 'length': 1 };
+ data = { 'object': object, 'path': path, 'pool': [object] };
+ queue = [];
// a non-recursive solution to avoid call stack limits
// http://www.jslab.dk/articles/non.recursive.preorder.traversal.part4
- while ((data = queue[++index])) {
+ do {
object = data.object;
path = data.path;
separator = path ? '.' : '';
- delete queue[index - 1];
forOwn(object, function(value, key) {
// inspect objects
@@ -490,11 +490,10 @@
pooled = filterOne(pool, function(data) {
return value == data.object;
});
-
// add to the "call" queue
if (!pooled) {
pool.push({ 'object': value, 'path': path + separator + key, 'pool': pool });
- queue[queue.length++] = pool[pool.length - 1];
+ queue[queue.length] = pool[pool.length - 1];
}
}
// if filter passed, log it
@@ -510,7 +509,7 @@
}
} catch(e) { }
});
- }
+ } while ((data = queue[index++]));
}
return result;
}

0 comments on commit 631eb4c

Please sign in to comment.