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.
Showing
1 changed file
with
11 additions
and
0 deletions
... | @@ -44,11 +44,22 @@ | ... | @@ -44,11 +44,22 @@ |
44 | if (!callbacks) { | 44 | if (!callbacks) { |
45 | return; | 45 | return; |
46 | } | 46 | } |
47 | // Slicing the arguments on every invocation of this method | ||
48 | // can add a significant amount of overhead. Avoid the | ||
49 | // intermediate object creation for the common case of a | ||
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 { | ||
47 | args = Array.prototype.slice.call(arguments, 1); | 57 | args = Array.prototype.slice.call(arguments, 1); |
48 | length = callbacks.length; | 58 | length = callbacks.length; |
49 | for (i = 0; i < length; ++i) { | 59 | for (i = 0; i < length; ++i) { |
50 | callbacks[i].apply(this, args); | 60 | callbacks[i].apply(this, args); |
51 | } | 61 | } |
62 | } | ||
52 | }; | 63 | }; |
53 | /** | 64 | /** |
54 | * Destroys the stream and cleans up. | 65 | * Destroys the stream and cleans up. | ... | ... |
-
Please register or sign in to post a comment