From 780e5d33a404af871748aba4eed2347b35cd8b17 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Mon, 25 Sep 2023 02:19:04 +0700 Subject: [PATCH] Slightly speed up [all[shadows+tiddlers]] filters (#7702) The `all` filter operator has shortcuts to optimise common patterns like `[all[shadows+tiddlers]]` or `[all[tiddlers]]`. In those cases, the filter operator function returns early and never uses the `result` linked list that was created, so it's immediately garbage-collected. Let's delay creating it until we know it's actually going to be used. --- core/modules/filters/all.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/modules/filters/all.js b/core/modules/filters/all.js index a36749e92..3554a74b3 100644 --- a/core/modules/filters/all.js +++ b/core/modules/filters/all.js @@ -28,12 +28,8 @@ function getAllFilterOperators() { Export our filter function */ exports.all = function(source,operator,options) { - // Get our suboperators - var allFilterOperators = getAllFilterOperators(); - // Cycle through the suboperators accumulating their results - var results = new $tw.utils.LinkedList(), - subops = operator.operand.split("+"); // Check for common optimisations + var subops = operator.operand.split("+"); if(subops.length === 1 && subops[0] === "") { return source; } else if(subops.length === 1 && subops[0] === "tiddlers") { @@ -46,6 +42,10 @@ exports.all = function(source,operator,options) { return options.wiki.eachShadowPlusTiddlers; } // Do it the hard way + // Get our suboperators + var allFilterOperators = getAllFilterOperators(); + // Cycle through the suboperators accumulating their results + var results = new $tw.utils.LinkedList(); for(var t=0; t