From 75b501f68140cc975b75217c1e41fcc582e256ea Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sun, 19 Feb 2017 18:08:15 +0000 Subject: [PATCH] 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() ``` --- boot/boot.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index e5128c225..3a2d3d765 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -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);