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.
* 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
// ==/UserScript==
/*
* 4chan X - Version 1.2.24 - 2013-07-25
* 4chan X - Version 1.2.24 - 2013-07-29
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -7945,53 +7945,39 @@
post: {},
file: {},
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'];
for (boardID in _ref) {
data = _ref[boardID];
for (type in data) {
id = data[type];
_ref1 = Redirect.archives;
for (name in _ref1) {
archive = _ref1[name];
if (name !== id || type === 'post' && archive.software !== 'foolfuuka') {
if (archive = Redirect.archives[id]) {
boards = archive[type] || archive['boards'];
if (!boards.contains(boardID)) {
continue;
}
arr = type === 'file' ? archive.files : archive.boards;
if (arr.contains(boardID)) {
Redirect[type][boardID] = archive;
}
Redirect[type][boardID] = archive;
}
}
}
_ref2 = Redirect.archives;
_results = [];
for (name in _ref2) {
archive = _ref2[name];
_results.push((function() {
var _i, _len, _ref3, _results1;
_ref3 = archive.boards;
_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);
}
_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.thread)) {
Redirect.thread[boardID] = archive;
}
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: {
'Foolz': {

View File

@ -1,6 +1,6 @@
// 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.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -7926,53 +7926,39 @@
post: {},
file: {},
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'];
for (boardID in _ref) {
data = _ref[boardID];
for (type in data) {
id = data[type];
_ref1 = Redirect.archives;
for (name in _ref1) {
archive = _ref1[name];
if (name !== id || type === 'post' && archive.software !== 'foolfuuka') {
if (archive = Redirect.archives[id]) {
boards = archive[type] || archive['boards'];
if (!boards.contains(boardID)) {
continue;
}
arr = type === 'file' ? archive.files : archive.boards;
if (arr.contains(boardID)) {
Redirect[type][boardID] = archive;
}
Redirect[type][boardID] = archive;
}
}
}
_ref2 = Redirect.archives;
_results = [];
for (name in _ref2) {
archive = _ref2[name];
_results.push((function() {
var _i, _len, _ref3, _results1;
_ref3 = archive.boards;
_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);
}
_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.thread)) {
Redirect.thread[boardID] = archive;
}
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: {
'Foolz': {

View File

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