b4175dda by David LaPalomento

Speed up Stream.trigger()

Profiling showed that trigger was consistently the longest running method during transmuxing. Inline the common case of passing a single argument to avoid slicing the arguments object. Allow grunt-contrib-connect to respond to external requests for easier demoing of mse-demo.html.
1 parent 6bbe1a3d
......@@ -44,10 +44,21 @@
if (!callbacks) {
return;
}
args = Array.prototype.slice.call(arguments, 1);
length = callbacks.length;
for (i = 0; i < length; ++i) {
callbacks[i].apply(this, args);
// Slicing the arguments on every invocation of this method
// can add a significant amount of overhead. Avoid the
// intermediate object creation for the common case of a
// single callback argument
if (arguments.length === 2) {
length = callbacks.length;
for (i = 0; i < length; ++i) {
callbacks[i].call(this, arguments[1]);
}
} else {
args = Array.prototype.slice.call(arguments, 1);
length = callbacks.length;
for (i = 0; i < length; ++i) {
callbacks[i].apply(this, args);
}
}
};
/**
......