mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-10-04 07:01:42 +00:00
Re-establish caching of results of parsing a tiddler
I switched this optimisation off back in
ed35d91be6, in October 2013, as part of a
big refactoring of the parsing and widget mechanism. I’ve been meaning
to switch it back on for some time.
My rough measurements suggest that this optimisation can reduce
rendering time by 5-10%.
This commit is contained in:
@@ -78,10 +78,13 @@ exports.parse = function() {
|
||||
}
|
||||
// Save the macro definition
|
||||
return [{
|
||||
type: "macrodef",
|
||||
name: this.match[1],
|
||||
params: params,
|
||||
text: text
|
||||
type: "set",
|
||||
attributes: {
|
||||
name: {type: "string", value: this.match[1]},
|
||||
value: {type: "string", value: text}
|
||||
},
|
||||
children: [],
|
||||
params: params
|
||||
}];
|
||||
};
|
||||
|
||||
|
||||
@@ -48,12 +48,13 @@ var WikiParser = function(type,text,options) {
|
||||
this.blockRules = this.instantiateRules(this.blockRuleClasses,"block",0);
|
||||
this.inlineRules = this.instantiateRules(this.inlineRuleClasses,"inline",0);
|
||||
// Parse any pragmas
|
||||
this.tree = this.parsePragmas();
|
||||
this.tree = [];
|
||||
var topBranch = this.parsePragmas();
|
||||
// Parse the text into inline runs or blocks
|
||||
if(options.parseAsInline) {
|
||||
this.tree.push.apply(this.tree,this.parseInlineRun());
|
||||
topBranch.push.apply(topBranch,this.parseInlineRun());
|
||||
} else {
|
||||
this.tree.push.apply(this.tree,this.parseBlocks());
|
||||
topBranch.push.apply(topBranch,this.parseBlocks());
|
||||
}
|
||||
// Return the parse tree
|
||||
};
|
||||
@@ -122,7 +123,7 @@ WikiParser.prototype.findNextMatch = function(rules,startPos) {
|
||||
Parse any pragmas at the beginning of a block of parse text
|
||||
*/
|
||||
WikiParser.prototype.parsePragmas = function() {
|
||||
var tree = [];
|
||||
var currentTreeBranch = this.tree;
|
||||
while(true) {
|
||||
// Skip whitespace
|
||||
this.skipWhitespace();
|
||||
@@ -137,9 +138,15 @@ WikiParser.prototype.parsePragmas = function() {
|
||||
break;
|
||||
}
|
||||
// Process the pragma rule
|
||||
tree.push.apply(tree,nextMatch.rule.parse());
|
||||
var subTree = nextMatch.rule.parse();
|
||||
if(subTree.length > 0) {
|
||||
// Quick hack; we only cope with a single parse tree node being returned, which is true at the moment
|
||||
currentTreeBranch.push.apply(currentTreeBranch,subTree);
|
||||
subTree[0].children = [];
|
||||
currentTreeBranch = subTree[0].children;
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
return currentTreeBranch;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user