From e4b10d42f9480c0505862a93f0b97d1c4270ed65 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 21 Dec 2017 16:13:47 +0000 Subject: [PATCH] Optimise the tag filter Spending a bit more time with Chrome dev tools, and further to 254e1ca, this optimisation reduces the rendering time for the sample TOC from 1.9s to about 0.9s... --- core/modules/filters/tag.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/modules/filters/tag.js b/core/modules/filters/tag.js index a421c61d7..a0093f565 100644 --- a/core/modules/filters/tag.js +++ b/core/modules/filters/tag.js @@ -25,17 +25,18 @@ exports.tag = function(source,operator,options) { }); } else { // Old semantics: + var tiddlers = options.wiki.getTiddlersWithTag(operator.operand); if(operator.prefix === "!") { // Returns a copy of the input if operator.operand is missing source(function(tiddler,title) { - if(tiddler && !tiddler.hasTag(operator.operand)) { + if(tiddlers.indexOf(title) === -1) { results.push(title); } }); } else { // Returns empty results if operator.operand is missing source(function(tiddler,title) { - if(tiddler && tiddler.hasTag(operator.operand)) { + if(tiddlers.indexOf(title) !== -1) { results.push(title); } });