mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Performance optimisations
In some situations, I’m seeing x2.5 speedups with these optimisations Starts fixing #1864
This commit is contained in:
parent
a86cfe2663
commit
c6e48ebc2d
12
boot/boot.js
12
boot/boot.js
@ -62,26 +62,26 @@ $tw.utils.isDate = function(value) {
|
||||
Iterate through all the own properties of an object or array. Callback is invoked with (element,title,object)
|
||||
*/
|
||||
$tw.utils.each = function(object,callback) {
|
||||
var next,f;
|
||||
var next,f,length;
|
||||
if(object) {
|
||||
if(Object.prototype.toString.call(object) == "[object Array]") {
|
||||
for (f=0; f<object.length; f++) {
|
||||
for (f=0, length=object.length; f<length; f++) {
|
||||
next = callback(object[f],f,object);
|
||||
if(next === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(f in object) {
|
||||
if(Object.prototype.hasOwnProperty.call(object,f)) {
|
||||
next = callback(object[f],f,object);
|
||||
var keys = Object.keys(object);
|
||||
for (f=0, length=keys.length; f<length; f++) {
|
||||
var key = keys[f];
|
||||
next = callback(object[key],key,object);
|
||||
if(next === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -16,13 +16,16 @@ Filter operator returning all the tags of the selected tiddlers
|
||||
Export our filter function
|
||||
*/
|
||||
exports.tags = function(source,operator,options) {
|
||||
var results = [];
|
||||
var tags = {};
|
||||
source(function(tiddler,title) {
|
||||
var t, length;
|
||||
if(tiddler && tiddler.fields.tags) {
|
||||
$tw.utils.pushTop(results,tiddler.fields.tags);
|
||||
for(t=0, length=tiddler.fields.tags.length; t<length; t++) {
|
||||
tags[tiddler.fields.tags[t]] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return results;
|
||||
return Object.keys(tags);
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -32,29 +32,39 @@ The exception is `skipWhiteSpace`, which just returns the position after the whi
|
||||
Look for a whitespace token. Returns null if not found, otherwise returns {type: "whitespace", start:, end:,}
|
||||
*/
|
||||
exports.parseWhiteSpace = function(source,pos) {
|
||||
var node = {
|
||||
type: "whitespace",
|
||||
start: pos
|
||||
};
|
||||
var re = /(\s)+/g;
|
||||
re.lastIndex = pos;
|
||||
var match = re.exec(source);
|
||||
if(match && match.index === pos) {
|
||||
node.end = pos + match[0].length;
|
||||
return node;
|
||||
var p = pos,c;
|
||||
while(true) {
|
||||
c = source.charAt(p);
|
||||
if((c === " ") || (c === "\f") || (c === "\n") || (c === "\r") || (c === "\t") || (c === "\v") || (c === "\u00a0")) { // Ignores some obscure unicode spaces
|
||||
p++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(p === pos) {
|
||||
return null;
|
||||
} else {
|
||||
return {
|
||||
type: "whitespace",
|
||||
start: pos,
|
||||
end: p
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Convenience wrapper for parseWhiteSpace. Returns the position after the whitespace
|
||||
*/
|
||||
exports.skipWhiteSpace = function(source,pos) {
|
||||
var whitespace = $tw.utils.parseWhiteSpace(source,pos);
|
||||
if(whitespace) {
|
||||
return whitespace.end;
|
||||
}
|
||||
var c;
|
||||
while(true) {
|
||||
c = source.charAt(pos);
|
||||
if((c === " ") || (c === "\f") || (c === "\n") || (c === "\r") || (c === "\t") || (c === "\v") || (c === "\u00a0")) { // Ignores some obscure unicode spaces
|
||||
pos++;
|
||||
} else {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -18,7 +18,7 @@ exports.after = ["load-modules"];
|
||||
exports.synchronous = true;
|
||||
|
||||
// Set to `true` to enable performance instrumentation
|
||||
var PERFORMANCE_INSTRUMENTATION = false;
|
||||
var PERFORMANCE_INSTRUMENTATION = true;
|
||||
|
||||
var widget = require("$:/core/modules/widgets/widget.js");
|
||||
|
||||
|
@ -621,6 +621,7 @@ exports.getTiddlerData = function(titleOrTiddler,defaultData) {
|
||||
tiddler = this.getTiddler(tiddler);
|
||||
}
|
||||
if(tiddler && tiddler.fields.text) {
|
||||
return this.getCacheForTiddler(tiddler.fields.title,"data",function() {
|
||||
switch(tiddler.fields.type) {
|
||||
case "application/json":
|
||||
// JSON tiddler
|
||||
@ -633,6 +634,7 @@ exports.getTiddlerData = function(titleOrTiddler,defaultData) {
|
||||
case "application/x-tiddler-dictionary":
|
||||
return $tw.utils.parseFields(tiddler.fields.text);
|
||||
}
|
||||
});
|
||||
}
|
||||
return defaultData;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user