mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-06-03 23:24:07 +00:00
Optimise iterating through tiddlers
Astonishingly, it’s much quicker to use `Object.keys()` to get an array of key names, and then iterate through that. I’m seeing 25% speed improvements for an empty tiddler iterator.
This commit is contained in:
parent
8bfc6f3557
commit
8f63e2a959
28
boot/boot.js
28
boot/boot.js
@ -910,7 +910,10 @@ $tw.Wiki = function(options) {
|
|||||||
|
|
||||||
// Iterate through all tiddler titles
|
// Iterate through all tiddler titles
|
||||||
this.each = function(callback) {
|
this.each = function(callback) {
|
||||||
for(var title in tiddlers) {
|
var titles = Object.keys(tiddlers),
|
||||||
|
index,titlesLength,title;
|
||||||
|
for(index = 0, titlesLength = titles.length; index < titlesLength; index++) {
|
||||||
|
title = titles[index];
|
||||||
callback(tiddlers[title],title);
|
callback(tiddlers[title],title);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -922,7 +925,10 @@ $tw.Wiki = function(options) {
|
|||||||
|
|
||||||
// Iterate through all shadow tiddler titles
|
// Iterate through all shadow tiddler titles
|
||||||
this.eachShadow = function(callback) {
|
this.eachShadow = function(callback) {
|
||||||
for(var title in shadowTiddlers) {
|
var titles = Object.keys(shadowTiddlers),
|
||||||
|
index,titlesLength,title;
|
||||||
|
for(index = 0, titlesLength = titles.length; index < titlesLength; index++) {
|
||||||
|
title = titles[index];
|
||||||
var shadowInfo = shadowTiddlers[title];
|
var shadowInfo = shadowTiddlers[title];
|
||||||
callback(shadowInfo.tiddler,title);
|
callback(shadowInfo.tiddler,title);
|
||||||
}
|
}
|
||||||
@ -930,10 +936,15 @@ $tw.Wiki = function(options) {
|
|||||||
|
|
||||||
// Iterate through all tiddlers and then the shadows
|
// Iterate through all tiddlers and then the shadows
|
||||||
this.eachTiddlerPlusShadows = function(callback) {
|
this.eachTiddlerPlusShadows = function(callback) {
|
||||||
for(var title in tiddlers) {
|
var titles = Object.keys(tiddlers),
|
||||||
|
index,titlesLength,title;
|
||||||
|
for(index = 0, titlesLength = titles.length; index < titlesLength; index++) {
|
||||||
|
title = titles[index];
|
||||||
callback(tiddlers[title],title);
|
callback(tiddlers[title],title);
|
||||||
}
|
}
|
||||||
for(var title in shadowTiddlers) {
|
titles = Object.keys(shadowTiddlers);
|
||||||
|
for(index = 0, titlesLength = titles.length; index < titlesLength; index++) {
|
||||||
|
title = titles[index];
|
||||||
if(!Object.prototype.hasOwnProperty.call(tiddlers,title)) {
|
if(!Object.prototype.hasOwnProperty.call(tiddlers,title)) {
|
||||||
var shadowInfo = shadowTiddlers[title];
|
var shadowInfo = shadowTiddlers[title];
|
||||||
callback(shadowInfo.tiddler,title);
|
callback(shadowInfo.tiddler,title);
|
||||||
@ -943,7 +954,10 @@ $tw.Wiki = function(options) {
|
|||||||
|
|
||||||
// Iterate through all the shadows and then the tiddlers
|
// Iterate through all the shadows and then the tiddlers
|
||||||
this.eachShadowPlusTiddlers = function(callback) {
|
this.eachShadowPlusTiddlers = function(callback) {
|
||||||
for(var title in shadowTiddlers) {
|
var titles = Object.keys(shadowTiddlers),
|
||||||
|
index,titlesLength,title;
|
||||||
|
for(index = 0, titlesLength = titles.length; index < titlesLength; index++) {
|
||||||
|
title = titles[index];
|
||||||
if(Object.prototype.hasOwnProperty.call(tiddlers,title)) {
|
if(Object.prototype.hasOwnProperty.call(tiddlers,title)) {
|
||||||
callback(tiddlers[title],title);
|
callback(tiddlers[title],title);
|
||||||
} else {
|
} else {
|
||||||
@ -951,7 +965,9 @@ $tw.Wiki = function(options) {
|
|||||||
callback(shadowInfo.tiddler,title);
|
callback(shadowInfo.tiddler,title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(var title in tiddlers) {
|
titles = Object.keys(tiddlers);
|
||||||
|
for(index = 0, titlesLength = titles.length; index < titlesLength; index++) {
|
||||||
|
title = titles[index];
|
||||||
if(!Object.prototype.hasOwnProperty.call(shadowTiddlers,title)) {
|
if(!Object.prototype.hasOwnProperty.call(shadowTiddlers,title)) {
|
||||||
callback(tiddlers[title],title);
|
callback(tiddlers[title],title);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user