mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-25 19:54:52 +00:00
Performance optimisations
In some situations, I’m seeing x2.5 speedups with these optimisations Starts fixing #1864
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/*
|
||||
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;
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user