From e9d8547a81b5feab3ae42b5d27c0f76ee8b6da87 Mon Sep 17 00:00:00 2001 From: Cameron Fischer Date: Thu, 16 Sep 2021 17:22:44 -0400 Subject: [PATCH] Optimise LinkedList filter ops to return iterator instead of array (#6035) * filter ops don't LinkedList to array anymore * LL.tiddlerIterator -> LL.makeTiddlerIterator LinkedList method name change. --- core/modules/filters/all.js | 2 +- core/modules/filters/links.js | 2 +- core/modules/utils/linked-list.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/modules/filters/all.js b/core/modules/filters/all.js index 853fe0a7f..a36749e92 100644 --- a/core/modules/filters/all.js +++ b/core/modules/filters/all.js @@ -52,7 +52,7 @@ exports.all = function(source,operator,options) { results.pushTop(subop(source,operator.prefix,options)); } } - return results.toArray(); + return results.makeTiddlerIterator(options.wiki); }; })(); diff --git a/core/modules/filters/links.js b/core/modules/filters/links.js index e1a859bc1..0305f4b7f 100644 --- a/core/modules/filters/links.js +++ b/core/modules/filters/links.js @@ -20,7 +20,7 @@ exports.links = function(source,operator,options) { source(function(tiddler,title) { results.pushTop(options.wiki.getTiddlerLinks(title)); }); - return results.toArray(); + return results.makeTiddlerIterator(options.wiki); }; })(); diff --git a/core/modules/utils/linked-list.js b/core/modules/utils/linked-list.js index 06242b454..dca096419 100644 --- a/core/modules/utils/linked-list.js +++ b/core/modules/utils/linked-list.js @@ -95,6 +95,15 @@ LinkedList.prototype.toArray = function() { return output; }; +LinkedList.prototype.makeTiddlerIterator = function(wiki) { + var self = this; + return function(callback) { + self.each(function(title) { + callback(wiki.getTiddler(title),title); + }); + }; +}; + function _removeOne(list,value) { var prevEntry = list.prev[value], nextEntry = list.next[value],