Reduce loops in Redirect.init

This commit is contained in:
Zixaphir 2013-07-29 11:36:07 -07:00
parent 22fde6fdb0
commit 392d6e255e
4 changed files with 48 additions and 78 deletions

View File

@ -1,5 +1,5 @@
/* /*
* 4chan X - Version 1.2.24 - 2013-07-25 * 4chan X - Version 1.2.24 - 2013-07-29
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE

View File

@ -19,7 +19,7 @@
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC
// ==/UserScript== // ==/UserScript==
/* /*
* 4chan X - Version 1.2.24 - 2013-07-25 * 4chan X - Version 1.2.24 - 2013-07-29
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -7945,53 +7945,39 @@
post: {}, post: {},
file: {}, file: {},
init: function() { init: function() {
var archive, arr, boardID, data, id, name, type, _ref, _ref1, _ref2, _results; var archive, boardID, boards, data, id, name, type, _i, _len, _ref, _ref1, _ref2;
_ref = Conf['selectedArchives']; _ref = Conf['selectedArchives'];
for (boardID in _ref) { for (boardID in _ref) {
data = _ref[boardID]; data = _ref[boardID];
for (type in data) { for (type in data) {
id = data[type]; id = data[type];
_ref1 = Redirect.archives; if (archive = Redirect.archives[id]) {
for (name in _ref1) { boards = archive[type] || archive['boards'];
archive = _ref1[name]; if (!boards.contains(boardID)) {
if (name !== id || type === 'post' && archive.software !== 'foolfuuka') {
continue; continue;
} }
arr = type === 'file' ? archive.files : archive.boards; Redirect[type][boardID] = archive;
if (arr.contains(boardID)) {
Redirect[type][boardID] = archive;
}
} }
} }
} }
_ref2 = Redirect.archives; _ref1 = Redirect.archives;
_results = []; for (name in _ref1) {
for (name in _ref2) { archive = _ref1[name];
archive = _ref2[name]; _ref2 = archive.boards;
_results.push((function() { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
var _i, _len, _ref3, _results1; boardID = _ref2[_i];
if (!(boardID in Redirect.thread)) {
_ref3 = archive.boards; Redirect.thread[boardID] = archive;
_results1 = [];
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
boardID = _ref3[_i];
if (!(boardID in Redirect.thread)) {
Redirect.thread[boardID] = archive;
}
if (!(boardID in Redirect.post || archive.software !== 'foolfuuka')) {
Redirect.post[boardID] = archive;
}
if (!(boardID in Redirect.file || !archive.files.contains(boardID))) {
_results1.push(Redirect.file[boardID] = archive);
} else {
_results1.push(void 0);
}
} }
return _results1; if (!(boardID in Redirect.post || archive.software !== 'foolfuuka')) {
})()); Redirect.post[boardID] = archive;
}
if (!(boardID in Redirect.file || !archive.files.contains(boardID))) {
Redirect.file[boardID] = archive;
}
}
} }
return _results;
}, },
archives: { archives: {
'Foolz': { 'Foolz': {

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript // Generated by CoffeeScript
/* /*
* 4chan X - Version 1.2.24 - 2013-07-25 * 4chan X - Version 1.2.24 - 2013-07-29
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -7926,53 +7926,39 @@
post: {}, post: {},
file: {}, file: {},
init: function() { init: function() {
var archive, arr, boardID, data, id, name, type, _ref, _ref1, _ref2, _results; var archive, boardID, boards, data, id, name, type, _i, _len, _ref, _ref1, _ref2;
_ref = Conf['selectedArchives']; _ref = Conf['selectedArchives'];
for (boardID in _ref) { for (boardID in _ref) {
data = _ref[boardID]; data = _ref[boardID];
for (type in data) { for (type in data) {
id = data[type]; id = data[type];
_ref1 = Redirect.archives; if (archive = Redirect.archives[id]) {
for (name in _ref1) { boards = archive[type] || archive['boards'];
archive = _ref1[name]; if (!boards.contains(boardID)) {
if (name !== id || type === 'post' && archive.software !== 'foolfuuka') {
continue; continue;
} }
arr = type === 'file' ? archive.files : archive.boards; Redirect[type][boardID] = archive;
if (arr.contains(boardID)) {
Redirect[type][boardID] = archive;
}
} }
} }
} }
_ref2 = Redirect.archives; _ref1 = Redirect.archives;
_results = []; for (name in _ref1) {
for (name in _ref2) { archive = _ref1[name];
archive = _ref2[name]; _ref2 = archive.boards;
_results.push((function() { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
var _i, _len, _ref3, _results1; boardID = _ref2[_i];
if (!(boardID in Redirect.thread)) {
_ref3 = archive.boards; Redirect.thread[boardID] = archive;
_results1 = [];
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
boardID = _ref3[_i];
if (!(boardID in Redirect.thread)) {
Redirect.thread[boardID] = archive;
}
if (!(boardID in Redirect.post || archive.software !== 'foolfuuka')) {
Redirect.post[boardID] = archive;
}
if (!(boardID in Redirect.file || !archive.files.contains(boardID))) {
_results1.push(Redirect.file[boardID] = archive);
} else {
_results1.push(void 0);
}
} }
return _results1; if (!(boardID in Redirect.post || archive.software !== 'foolfuuka')) {
})()); Redirect.post[boardID] = archive;
}
if (!(boardID in Redirect.file || !archive.files.contains(boardID))) {
Redirect.file[boardID] = archive;
}
}
} }
return _results;
}, },
archives: { archives: {
'Foolz': { 'Foolz': {

View File

@ -6,13 +6,10 @@ Redirect =
init: -> init: ->
for boardID, data of Conf['selectedArchives'] for boardID, data of Conf['selectedArchives']
for type, id of data for type, id of data
for name, archive of Redirect.archives if archive = Redirect.archives[id]
continue if name isnt id or type is 'post' and archive.software isnt 'foolfuuka' boards = archive[type] or archive['boards']
arr = if type is 'file' continue unless boards.contains boardID
archive.files Redirect[type][boardID] = archive
else
archive.boards
Redirect[type][boardID] = archive if arr.contains boardID
for name, archive of Redirect.archives for name, archive of Redirect.archives
for boardID in archive.boards for boardID in archive.boards
unless boardID of Redirect.thread unless boardID of Redirect.thread
@ -21,6 +18,7 @@ Redirect =
Redirect.post[boardID] = archive Redirect.post[boardID] = archive
unless boardID of Redirect.file or !archive.files.contains boardID unless boardID of Redirect.file or !archive.files.contains boardID
Redirect.file[boardID] = archive Redirect.file[boardID] = archive
return
archives: archives:
'Foolz': 'Foolz':