1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-25 01:20:30 +00:00

Optimise getStateQualifier()

Another fix for #1864, this time we’re caching state qualifiers as they
are expensive to compute.
This commit is contained in:
Jermolene 2015-07-06 11:23:12 +01:00
parent c6e48ebc2d
commit 848a7f4e74

View File

@ -195,7 +195,11 @@ Widget.prototype.hasVariable = function(name,value) {
Construct a qualifying string based on a hash of concatenating the values of a given variable in the parent chain Construct a qualifying string based on a hash of concatenating the values of a given variable in the parent chain
*/ */
Widget.prototype.getStateQualifier = function(name) { Widget.prototype.getStateQualifier = function(name) {
this.qualifiers = this.qualifiers || Object.create(null);
name = name || "transclusion"; name = name || "transclusion";
if(this.qualifiers[name]) {
return this.qualifiers[name];
} else {
var output = [], var output = [],
node = this; node = this;
while(node && node.parentWidget) { while(node && node.parentWidget) {
@ -204,7 +208,10 @@ Widget.prototype.getStateQualifier = function(name) {
} }
node = node.parentWidget; node = node.parentWidget;
} }
return $tw.utils.hashString(output.join("")); var value = $tw.utils.hashString(output.join(""));
this.qualifiers[name] = value;
return value;
}
}; };
/* /*