forEach is actually slow.

This commit is contained in:
Nicolas Stepien 2011-11-24 01:43:21 +01:00
parent f40d40a7d6
commit 357c6155d6
2 changed files with 22 additions and 12 deletions

View File

@ -2908,7 +2908,7 @@
} }
}, },
onLoad: function() { onLoad: function() {
var nodes; var callback, node, nodes, _i, _j, _len, _len2, _ref;
$.off(d, 'DOMContentLoaded', Main.onLoad); $.off(d, 'DOMContentLoaded', Main.onLoad);
if (conf['404 Redirect'] && d.title === '4chan - 404' && /^\d+$/.test(g.THREAD_ID)) { if (conf['404 Redirect'] && d.title === '4chan - 404' && /^\d+$/.test(g.THREAD_ID)) {
redirect(); redirect();
@ -2936,13 +2936,18 @@
if (conf['Index Navigation']) nav.init(); if (conf['Index Navigation']) nav.init();
} }
nodes = $$('.op, a + table'); nodes = $$('.op, a + table');
g.callbacks.forEach(function(callback) { _ref = g.callbacks;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
callback = _ref[_i];
try { try {
return nodes.forEach(callback); for (_j = 0, _len2 = nodes.length; _j < _len2; _j++) {
node = nodes[_j];
callback(node);
}
} catch (err) { } catch (err) {
return alert(err); alert(err);
} }
}); }
$.on($('form[name=delform]'), 'DOMNodeInserted', Main.node); $.on($('form[name=delform]'), 'DOMNodeInserted', Main.node);
return options.init(); return options.init();
}, },
@ -2952,16 +2957,20 @@
if (origin === 'http://sys.4chan.org') return QR.receive(data); if (origin === 'http://sys.4chan.org') return QR.receive(data);
}, },
node: function(e) { node: function(e) {
var target; var callback, target, _i, _len, _ref, _results;
target = e.target; target = e.target;
if (target.nodeName !== 'TABLE') return; if (target.nodeName !== 'TABLE') return;
return g.callbacks.forEach(function(callback) { _ref = g.callbacks;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
callback = _ref[_i];
try { try {
return callback(target); _results.push(callback(target));
} catch (err) { } catch (err) {
} }
}); }
return _results;
}, },
css: '\ css: '\
/* dialog styling */\ /* dialog styling */\

View File

@ -2307,9 +2307,10 @@ Main =
nodes = $$ '.op, a + table' nodes = $$ '.op, a + table'
g.callbacks.forEach (callback) -> for callback in g.callbacks
try try
nodes.forEach callback for node in nodes
callback node
catch err catch err
alert err alert err
$.on $('form[name=delform]'), 'DOMNodeInserted', Main.node $.on $('form[name=delform]'), 'DOMNodeInserted', Main.node
@ -2323,7 +2324,7 @@ Main =
node: (e) -> node: (e) ->
{target} = e {target} = e
return unless target.nodeName is 'TABLE' return unless target.nodeName is 'TABLE'
g.callbacks.forEach (callback) -> for callback in g.callbacks
try try
callback target callback target
catch err catch err