1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 02:19:55 +00:00

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
This commit is contained in:
Tobias Beer 2015-01-27 01:17:14 +01:00
parent c3cbbc3f66
commit a88ead9c0f

View File

@ -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;
};