1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Taking advantage of linkedLists in all operator (#5362)

* Taking advantage of linkedLists in all operator

* Test to confirm [all[]] with LinkList is the same
This commit is contained in:
Cameron Fischer 2021-01-04 03:38:50 -05:00 committed by GitHub
parent ac40ee4246
commit be70e5851d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -31,7 +31,7 @@ exports.all = function(source,operator,options) {
// Get our suboperators // Get our suboperators
var allFilterOperators = getAllFilterOperators(); var allFilterOperators = getAllFilterOperators();
// Cycle through the suboperators accumulating their results // Cycle through the suboperators accumulating their results
var results = [], var results = new $tw.utils.LinkedList(),
subops = operator.operand.split("+"); subops = operator.operand.split("+");
// Check for common optimisations // Check for common optimisations
if(subops.length === 1 && subops[0] === "") { if(subops.length === 1 && subops[0] === "") {
@ -49,10 +49,10 @@ exports.all = function(source,operator,options) {
for(var t=0; t<subops.length; t++) { for(var t=0; t<subops.length; t++) {
var subop = allFilterOperators[subops[t]]; var subop = allFilterOperators[subops[t]];
if(subop) { if(subop) {
$tw.utils.pushTop(results,subop(source,operator.prefix,options)); results.pushTop(subop(source,operator.prefix,options));
} }
} }
return results; return results.toArray();
}; };
})(); })();

View File

@ -306,6 +306,7 @@ function runTests(wiki) {
expect(wiki.filterTiddlers("[all[shadows+tiddlers]]").join(",")).toBe("$:/TiddlerFive,TiddlerSix,TiddlerSeventh,Tiddler8,$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test"); expect(wiki.filterTiddlers("[all[shadows+tiddlers]]").join(",")).toBe("$:/TiddlerFive,TiddlerSix,TiddlerSeventh,Tiddler8,$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test");
expect(wiki.filterTiddlers("[all[tiddlers+shadows]]").join(",")).toBe("$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test,$:/TiddlerFive,TiddlerSix,TiddlerSeventh,Tiddler8"); expect(wiki.filterTiddlers("[all[tiddlers+shadows]]").join(",")).toBe("$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test,$:/TiddlerFive,TiddlerSix,TiddlerSeventh,Tiddler8");
expect(wiki.filterTiddlers("[all[tiddlers]tag[two]]").join(",")).toBe("$:/TiddlerTwo,Tiddler Three"); expect(wiki.filterTiddlers("[all[tiddlers]tag[two]]").join(",")).toBe("$:/TiddlerTwo,Tiddler Three");
expect(wiki.filterTiddlers("[all[orphans+tiddlers+tags]]").join(",")).toBe("$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,hasList,has filter,filter regexp test,two,one");
}); });
it("should handle the tags operator", function() { it("should handle the tags operator", function() {