mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 01:57:19 +00:00
Optimise $tw.utils.parseStringArray()
On my machine, the following test performed on the prerelease improves from 40ms to 8ms with this patch: ``` var a = $tw.utils.stringifyList($tw.wiki.allTitles());console.time();$tw.utils.p arseStringArray(a);console.timeEnd() ```
This commit is contained in:
parent
daf703b67f
commit
75b501f681
@ -271,14 +271,15 @@ $tw.utils.stringifyList = function(value) {
|
||||
$tw.utils.parseStringArray = function(value) {
|
||||
if(typeof value === "string") {
|
||||
var memberRegExp = /(?:^|[^\S\xA0])(?:\[\[(.*?)\]\])(?=[^\S\xA0]|$)|([\S\xA0]+)/mg,
|
||||
results = [],
|
||||
results = [], names = {},
|
||||
match;
|
||||
do {
|
||||
match = memberRegExp.exec(value);
|
||||
if(match) {
|
||||
var item = match[1] || match[2];
|
||||
if(item !== undefined && results.indexOf(item) === -1) {
|
||||
if(item !== undefined && !$tw.utils.hop(names,item)) {
|
||||
results.push(item);
|
||||
names[item] = true;
|
||||
}
|
||||
}
|
||||
} while(match);
|
||||
|
Loading…
Reference in New Issue
Block a user