From ddabad15e9e0eecdffc3a07c20402226e4b9935b Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 7 Jan 2014 08:03:23 -0700 Subject: [PATCH] Small optimization to Redirect code --- LICENSE | 2 +- builds/4chan-X.user.js | 47 +++++++++++++++++-------------------- builds/crx/script.js | 47 +++++++++++++++++-------------------- src/Archive/Redirect.coffee | 36 ++++++++++++++-------------- 4 files changed, 64 insertions(+), 68 deletions(-) diff --git a/LICENSE b/LICENSE index f27731086..fb1558cdc 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.2.44 - 2014-01-06 +* 4chan X - Version 1.2.44 - 2014-01-07 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 48ea00c3a..7b7a2f6a3 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -22,7 +22,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.2.44 - 2014-01-06 +* 4chan X - Version 1.2.44 - 2014-01-07 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -9755,44 +9755,41 @@ }; Redirect = { - data: { - thread: {}, - post: {}, - file: {} - }, init: function() { - var archive, boardID, boards, data, id, name, type, _i, _len, _ref, _ref1, _ref2; + var archive, archives, boardID, data, id, name, o, type, _i, _len, _ref, _ref1; + o = { + thread: {}, + post: {}, + file: {} + }; + archives = Redirect.archives; _ref = Conf['selectedArchives']; for (boardID in _ref) { data = _ref[boardID]; for (type in data) { id = data[type]; - if (archive = Redirect.archives[id]) { - boards = archive[type] || archive['boards']; - if (__indexOf.call(boards, boardID) < 0) { - continue; - } - Redirect.data[type][boardID] = archive; + if ((archive = archives[id]) && __indexOf.call(archive[type] || archive['boards'], boardID) >= 0) { + o[type][boardID] = archive; } } } - _ref1 = Redirect.archives; - for (name in _ref1) { - archive = _ref1[name]; - _ref2 = archive.boards; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - boardID = _ref2[_i]; - if (!(boardID in Redirect.data.thread)) { - Redirect.data.thread[boardID] = archive; + for (name in archives) { + archive = archives[name]; + _ref1 = archive.boards; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + boardID = _ref1[_i]; + if (!(boardID in o.thread)) { + o.thread[boardID] = archive; } - if (!(boardID in Redirect.data.post || archive.software !== 'foolfuuka')) { - Redirect.data.post[boardID] = archive; + if (!(boardID in o.post || archive.software !== 'foolfuuka')) { + o.post[boardID] = archive; } - if (!(boardID in Redirect.data.file || __indexOf.call(archive.files, boardID) < 0)) { - Redirect.data.file[boardID] = archive; + if (!(boardID in o.file || __indexOf.call(archive.files, boardID) < 0)) { + o.file[boardID] = archive; } } } + return Redirect.data = o; }, archives: { "Foolz": { diff --git a/builds/crx/script.js b/builds/crx/script.js index fb2328d4a..2115d8141 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.2.44 - 2014-01-06 +* 4chan X - Version 1.2.44 - 2014-01-07 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -9744,44 +9744,41 @@ }; Redirect = { - data: { - thread: {}, - post: {}, - file: {} - }, init: function() { - var archive, boardID, boards, data, id, name, type, _i, _len, _ref, _ref1, _ref2; + var archive, archives, boardID, data, id, name, o, type, _i, _len, _ref, _ref1; + o = { + thread: {}, + post: {}, + file: {} + }; + archives = Redirect.archives; _ref = Conf['selectedArchives']; for (boardID in _ref) { data = _ref[boardID]; for (type in data) { id = data[type]; - if (archive = Redirect.archives[id]) { - boards = archive[type] || archive['boards']; - if (__indexOf.call(boards, boardID) < 0) { - continue; - } - Redirect.data[type][boardID] = archive; + if ((archive = archives[id]) && __indexOf.call(archive[type] || archive['boards'], boardID) >= 0) { + o[type][boardID] = archive; } } } - _ref1 = Redirect.archives; - for (name in _ref1) { - archive = _ref1[name]; - _ref2 = archive.boards; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - boardID = _ref2[_i]; - if (!(boardID in Redirect.data.thread)) { - Redirect.data.thread[boardID] = archive; + for (name in archives) { + archive = archives[name]; + _ref1 = archive.boards; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + boardID = _ref1[_i]; + if (!(boardID in o.thread)) { + o.thread[boardID] = archive; } - if (!(boardID in Redirect.data.post || archive.software !== 'foolfuuka')) { - Redirect.data.post[boardID] = archive; + if (!(boardID in o.post || archive.software !== 'foolfuuka')) { + o.post[boardID] = archive; } - if (!(boardID in Redirect.data.file || __indexOf.call(archive.files, boardID) < 0)) { - Redirect.data.file[boardID] = archive; + if (!(boardID in o.file || __indexOf.call(archive.files, boardID) < 0)) { + o.file[boardID] = archive; } } } + return Redirect.data = o; }, archives: { "Foolz": { diff --git a/src/Archive/Redirect.coffee b/src/Archive/Redirect.coffee index b6451c6fa..8d3a33253 100755 --- a/src/Archive/Redirect.coffee +++ b/src/Archive/Redirect.coffee @@ -1,25 +1,27 @@ Redirect = - data: - thread: {} - post: {} - file: {} init: -> + o = + thread: {} + post: {} + file: {} + + {archives} = Redirect + for boardID, data of Conf['selectedArchives'] - for type, id of data - if archive = Redirect.archives[id] - boards = archive[type] or archive['boards'] - continue unless boardID in boards - Redirect.data[type][boardID] = archive - for name, archive of Redirect.archives + for type, id of data when (archive = archives[id]) and boardID in (archive[type] or archive['boards']) + o[type][boardID] = archive + + for name, archive of archives for boardID in archive.boards - unless boardID of Redirect.data.thread - Redirect.data.thread[boardID] = archive - unless boardID of Redirect.data.post or archive.software isnt 'foolfuuka' - Redirect.data.post[boardID] = archive - unless boardID of Redirect.data.file or boardID not in archive.files - Redirect.data.file[boardID] = archive - return + unless boardID of o.thread + o.thread[boardID] = archive + unless boardID of o.post or archive.software isnt 'foolfuuka' + o.post[boardID] = archive + unless boardID of o.file or boardID not in archive.files + o.file[boardID] = archive + + Redirect.data = o archives: "Foolz":