performance boost

10.3.x-maintenance
cTn 2014-03-12 00:07:27 +01:00
parent 578937fd2c
commit b11a84217b
1 changed files with 7 additions and 10 deletions

View File

@ -447,22 +447,19 @@ MSP.process_data = function(code, message_buffer, message_length) {
} }
// trigger callbacks, cleanup/remove callback after trigger // trigger callbacks, cleanup/remove callback after trigger
for (var i = (this.callbacks.length - 1); i >= 0; i--) { // itterating in reverse because we use .splice which modifies array length for (var i = this.callbacks.length - 1; i >= 0; i--) { // itterating in reverse because we use .splice which modifies array length
if (this.callbacks[i].code == code) { if (this.callbacks[i].code == code) {
// saving current obj for after-callback comparison // save callback reference
var obj = this.callbacks[i]; var callback = this.callbacks[i].callback;
// remove timeout // remove timeout
clearInterval(obj.timer); clearInterval(this.callbacks[i].timer);
// fire callback
if (obj.callback) obj.callback({'command': code, 'data': data, 'length': message_length});
// remove object from array // remove object from array
// we need to check if the callback object still exists as it could have been touched/moved/removed in callback routine this.callbacks.splice(i, 1);
var index = this.callbacks.indexOf(obj);
if (index > -1) this.callbacks.splice(index, 1); // fire callback
if (callback) callback({'command': code, 'data': data, 'length': message_length});
} }
} }
}; };