Small optimization to Redirect code

This commit is contained in:
Zixaphir 2014-01-07 08:03:23 -07:00
parent 6d858de604
commit ddabad15e9
4 changed files with 64 additions and 68 deletions

View File

@ -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. * 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

@ -22,7 +22,7 @@
// ==/UserScript== // ==/UserScript==
/* /*
* 4chan X - Version 1.2.44 - 2014-01-06 * 4chan X - Version 1.2.44 - 2014-01-07
* *
* 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
@ -9755,44 +9755,41 @@
}; };
Redirect = { Redirect = {
data: {
thread: {},
post: {},
file: {}
},
init: function() { 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']; _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];
if (archive = Redirect.archives[id]) { if ((archive = archives[id]) && __indexOf.call(archive[type] || archive['boards'], boardID) >= 0) {
boards = archive[type] || archive['boards']; o[type][boardID] = archive;
if (__indexOf.call(boards, boardID) < 0) {
continue;
}
Redirect.data[type][boardID] = archive;
} }
} }
} }
_ref1 = Redirect.archives; for (name in archives) {
for (name in _ref1) { archive = archives[name];
archive = _ref1[name]; _ref1 = archive.boards;
_ref2 = archive.boards; for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { boardID = _ref1[_i];
boardID = _ref2[_i]; if (!(boardID in o.thread)) {
if (!(boardID in Redirect.data.thread)) { o.thread[boardID] = archive;
Redirect.data.thread[boardID] = archive;
} }
if (!(boardID in Redirect.data.post || archive.software !== 'foolfuuka')) { if (!(boardID in o.post || archive.software !== 'foolfuuka')) {
Redirect.data.post[boardID] = archive; o.post[boardID] = archive;
} }
if (!(boardID in Redirect.data.file || __indexOf.call(archive.files, boardID) < 0)) { if (!(boardID in o.file || __indexOf.call(archive.files, boardID) < 0)) {
Redirect.data.file[boardID] = archive; o.file[boardID] = archive;
} }
} }
} }
return Redirect.data = o;
}, },
archives: { archives: {
"Foolz": { "Foolz": {

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript // 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. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -9744,44 +9744,41 @@
}; };
Redirect = { Redirect = {
data: {
thread: {},
post: {},
file: {}
},
init: function() { 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']; _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];
if (archive = Redirect.archives[id]) { if ((archive = archives[id]) && __indexOf.call(archive[type] || archive['boards'], boardID) >= 0) {
boards = archive[type] || archive['boards']; o[type][boardID] = archive;
if (__indexOf.call(boards, boardID) < 0) {
continue;
}
Redirect.data[type][boardID] = archive;
} }
} }
} }
_ref1 = Redirect.archives; for (name in archives) {
for (name in _ref1) { archive = archives[name];
archive = _ref1[name]; _ref1 = archive.boards;
_ref2 = archive.boards; for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { boardID = _ref1[_i];
boardID = _ref2[_i]; if (!(boardID in o.thread)) {
if (!(boardID in Redirect.data.thread)) { o.thread[boardID] = archive;
Redirect.data.thread[boardID] = archive;
} }
if (!(boardID in Redirect.data.post || archive.software !== 'foolfuuka')) { if (!(boardID in o.post || archive.software !== 'foolfuuka')) {
Redirect.data.post[boardID] = archive; o.post[boardID] = archive;
} }
if (!(boardID in Redirect.data.file || __indexOf.call(archive.files, boardID) < 0)) { if (!(boardID in o.file || __indexOf.call(archive.files, boardID) < 0)) {
Redirect.data.file[boardID] = archive; o.file[boardID] = archive;
} }
} }
} }
return Redirect.data = o;
}, },
archives: { archives: {
"Foolz": { "Foolz": {

View File

@ -1,25 +1,27 @@
Redirect = Redirect =
data:
thread: {}
post: {}
file: {}
init: -> init: ->
o =
thread: {}
post: {}
file: {}
{archives} = Redirect
for boardID, data of Conf['selectedArchives'] for boardID, data of Conf['selectedArchives']
for type, id of data for type, id of data when (archive = archives[id]) and boardID in (archive[type] or archive['boards'])
if archive = Redirect.archives[id] o[type][boardID] = archive
boards = archive[type] or archive['boards']
continue unless boardID in boards for name, archive of archives
Redirect.data[type][boardID] = archive
for name, archive of Redirect.archives
for boardID in archive.boards for boardID in archive.boards
unless boardID of Redirect.data.thread unless boardID of o.thread
Redirect.data.thread[boardID] = archive o.thread[boardID] = archive
unless boardID of Redirect.data.post or archive.software isnt 'foolfuuka' unless boardID of o.post or archive.software isnt 'foolfuuka'
Redirect.data.post[boardID] = archive o.post[boardID] = archive
unless boardID of Redirect.data.file or boardID not in archive.files unless boardID of o.file or boardID not in archive.files
Redirect.data.file[boardID] = archive o.file[boardID] = archive
return
Redirect.data = o
archives: archives:
"Foolz": "Foolz":