performance boost
parent
578937fd2c
commit
b11a84217b
17
js/msp.js
17
js/msp.js
|
@ -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});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue