softTask optimizations.

This commit is contained in:
Zixaphir 2013-10-17 18:29:10 -07:00
parent c526b89c8d
commit fefe8a28a2
4 changed files with 60 additions and 65 deletions

View File

@ -1,5 +1,5 @@
/*
* appchan x - Version 2.4.1 - 2013-10-16
* appchan x - Version 2.4.1 - 2013-10-17
*
* Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE

View File

@ -20,7 +20,7 @@
// ==/UserScript==
/*
* appchan x - Version 2.4.1 - 2013-10-16
* appchan x - Version 2.4.1 - 2013-10-17
*
* Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -15953,26 +15953,8 @@
var errors, func, i, len, node, queue, softTask;
queue = [];
softTask = function() {
var args, func, task;
task = queue.shift();
func = task[0];
args = Array.prototype.slice.call(task, 1);
func.apply(func, args);
if (!queue.length) {
return;
}
if ((queue.length % 7) === 0) {
return setTimeout(softTask, 0);
} else {
return softTask();
}
};
len = nodes.length;
i = 0;
errors = null;
func = function(node, i) {
func = function(node) {
var callback, err, _i, _len, _ref;
_ref = klass.callbacks;
@ -15991,7 +15973,7 @@
});
}
}
if (i === len) {
if (!queue.length) {
if (errors) {
Main.handleErrors(errors);
}
@ -16000,9 +15982,25 @@
}
}
};
softTask = function() {
var node;
node = queue.shift();
func(node);
if (!queue.length) {
return;
}
if (!(queue.length % 7)) {
return setTimeout(softTask, 0);
} else {
return softTask();
}
};
len = nodes.length;
i = 0;
while (i < len) {
node = nodes[i];
queue.push([func, node, ++i]);
node = nodes[i++];
queue.push(node);
}
return softTask();
},

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
* appchan x - Version 2.4.1 - 2013-10-16
* appchan x - Version 2.4.1 - 2013-10-17
*
* Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -15941,26 +15941,8 @@
var errors, func, i, len, node, queue, softTask;
queue = [];
softTask = function() {
var args, func, task;
task = queue.shift();
func = task[0];
args = Array.prototype.slice.call(task, 1);
func.apply(func, args);
if (!queue.length) {
return;
}
if ((queue.length % 7) === 0) {
return setTimeout(softTask, 0);
} else {
return softTask();
}
};
len = nodes.length;
i = 0;
errors = null;
func = function(node, i) {
func = function(node) {
var callback, err, _i, _len, _ref;
_ref = klass.callbacks;
@ -15979,7 +15961,7 @@
});
}
}
if (i === len) {
if (!queue.length) {
if (errors) {
Main.handleErrors(errors);
}
@ -15988,9 +15970,25 @@
}
}
};
softTask = function() {
var node;
node = queue.shift();
func(node);
if (!queue.length) {
return;
}
if (!(queue.length % 7)) {
return setTimeout(softTask, 0);
} else {
return softTask();
}
};
len = nodes.length;
i = 0;
while (i < len) {
node = nodes[i];
queue.push([func, node, ++i]);
node = nodes[i++];
queue.push(node);
}
return softTask();
},

View File

@ -252,23 +252,9 @@ Main =
callbackNodesDB: (klass, nodes, cb) ->
queue = []
softTask = ->
task = queue.shift()
func = task[0]
args = Array::slice.call task, 1
func.apply func, args
return unless queue.length
if (queue.length % 7) is 0
setTimeout softTask, 0
else
softTask()
# get the nodes' length only once
len = nodes.length
i = 0
errors = null
func = (node, i) ->
func = (node) ->
for callback in klass.callbacks
try
callback.cb.call node
@ -279,13 +265,26 @@ Main =
message: "\"#{callback.name}\" crashed on #{klass.name} No.#{node} (/#{node.board}/)."
error: err
# finish
if i is len
unless queue.length
Main.handleErrors errors if errors
cb() if cb
softTask = ->
node = queue.shift()
func node
return unless queue.length
unless queue.length % 7
setTimeout softTask, 0
else
softTask()
# get the nodes' length only once
len = nodes.length
i = 0
while i < len
node = nodes[i]
queue.push [func, node, ++i]
node = nodes[i++]
queue.push node
softTask()