From a88ead9c0f857c34ae5d9ee27146386aee133b81 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Tue, 27 Jan 2015 01:17:14 +0100 Subject: [PATCH] removed conditional from iterator I'd really like to see a profiler run against the two to see the performance impact of one over the other --- core/modules/filters/each.js | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/core/modules/filters/each.js b/core/modules/filters/each.js index b492ed1e1..79a3981b9 100644 --- a/core/modules/filters/each.js +++ b/core/modules/filters/each.js @@ -19,21 +19,31 @@ Export our filter function exports.each = function(source,operator,options) { var results = [], values = {}, - list = "list" === operator.suffix; - source(function(tiddler,title) { - if(tiddler) { - var field = operator.operand || "title", - items = list ? - options.wiki.getTiddlerList(title,field) : - [ "title" === field ? title : tiddler.getFieldString(operator.operand)]; - $tw.utils.each(items,function(value){ - if(!$tw.utils.hop(values,value)) { - values[value] = true; - results.push(list ? value : title); - } - }); - } - }); + field = operator.operand || "title", + add = function(v) { + if(!$tw.utils.hop(values,v)) { + values[v] = true; + results.push(v); + } + }; + if("list" !== operator.suffix) { + source(function(tiddler,title) { + if(tiddler) { + add("title" === field ? title : tiddler.getFieldString(operator.operand)); + } + }); + } else { + source(function(tiddler,title) { + if(tiddler) { + $tw.utils.each( + options.wiki.getTiddlerList(title,field), + function(value) { + add(value); + } + ); + } + }); + } return results; };