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 @@ ...@@ -44,10 +44,21 @@
44 if (!callbacks) { 44 if (!callbacks) {
45 return; 45 return;
46 } 46 }
47 args = Array.prototype.slice.call(arguments, 1); 47 // Slicing the arguments on every invocation of this method
48 length = callbacks.length; 48 // can add a significant amount of overhead. Avoid the
49 for (i = 0; i < length; ++i) { 49 // intermediate object creation for the common case of a
50 callbacks[i].apply(this, args); 50 // single callback argument
51 if (arguments.length === 2) {
52 length = callbacks.length;
53 for (i = 0; i < length; ++i) {
54 callbacks[i].call(this, arguments[1]);
55 }
56 } else {
57 args = Array.prototype.slice.call(arguments, 1);
58 length = callbacks.length;
59 for (i = 0; i < length; ++i) {
60 callbacks[i].apply(this, args);
61 }
51 } 62 }
52 }; 63 };
53 /** 64 /**
......