aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2012-05-04 23:56:25 -0700
committerPhil Crosby2012-05-05 18:32:13 -0700
commit1b35b1c6b1ecb7c88b6d060de3cab0372928b4f1 (patch)
tree473ed34aa532ec7b793d10632e1eb6db9011e42b
parentc65c9d1724a7b97f49a701512711df18e182bc79 (diff)
downloadvimium-1b35b1c6b1ecb7c88b6d060de3cab0372928b4f1.tar.bz2
Make the bookmark flattening iterative; return the bookmarks instead of modifying an argument.
-rw-r--r--lib/completion.js19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/completion.js b/lib/completion.js
index 1f7aa2b8..fefa92fa 100644
--- a/lib/completion.js
+++ b/lib/completion.js
@@ -117,20 +117,23 @@ var completion = (function() {
/** A fuzzy bookmark completer */
var FuzzyBookmarkCompletionSource = AsyncCompletionSource.extend({
- traverseTree: function(bookmarks, results) {
- bookmarks.forEach(function(bookmark) {
+ // Traverses the bookmark hierarhcy and retuns a list of all bookmarks in the tree.
+ traverseBookmarkTree: function(bookmarks) {
+ var results = [];
+ var toVisit = bookmarks;
+ while (toVisit.length > 0) {
+ var bookmark = toVisit.shift();
results.push(bookmark);
- if (bookmark.children === undefined)
- return;
- this.traverseTree(bookmark.children, results);
- }.proxy(this));
+ if (bookmark.children)
+ toVisit.push.apply(toVisit, bookmark.children);
+ }
+ return results;
},
refresh: function() {
this.reset();
chrome.bookmarks.getTree(function(bookmarks) {
- var results = [];
- this.traverseTree(bookmarks, results);
+ var results = this.traverseBookmarkTree(bookmarks);
var validResults = results.filter(function(b) { return b.url !== undefined; });
var matches = validResults.map(
function(bookmark) { return this.createInternalMatch("bookmark", bookmark); }.proxy(this));