use regular for loops instead of for-in
for-in returns all enumerable properties on String, which fails for iteration when people set enumerable properties on String (not that this is a good idea). Using the normal for loop is probably faster, too.
Showing
1 changed file
with
5 additions
and
5 deletions
... | @@ -41,13 +41,13 @@ hls.FlvTag = function(type, extraData) { | ... | @@ -41,13 +41,13 @@ hls.FlvTag = function(type, extraData) { |
41 | // corresponding writes faster because we don't have to loop over the | 41 | // corresponding writes faster because we don't have to loop over the |
42 | // characters | 42 | // characters |
43 | // re-test with test/perf.html if you're planning on changing this | 43 | // re-test with test/perf.html if you're planning on changing this |
44 | for (i in 'width') { | 44 | for (i = 0; i < 'width'.length; i++) { |
45 | widthBytes[i] = 'width'.charCodeAt(i); | 45 | widthBytes[i] = 'width'.charCodeAt(i); |
46 | } | 46 | } |
47 | for (i in 'height') { | 47 | for (i = 0; i < 'height'.length; i++) { |
48 | heightBytes[i] = 'height'.charCodeAt(i); | 48 | heightBytes[i] = 'height'.charCodeAt(i); |
49 | } | 49 | } |
50 | for (i in 'videocodecid') { | 50 | for (i = 0; i < 'videocodecid'.length; i++) { |
51 | videocodecidBytes[i] = 'videocodecid'.charCodeAt(i); | 51 | videocodecidBytes[i] = 'videocodecid'.charCodeAt(i); |
52 | } | 52 | } |
53 | 53 | ||
... | @@ -199,7 +199,7 @@ hls.FlvTag = function(type, extraData) { | ... | @@ -199,7 +199,7 @@ hls.FlvTag = function(type, extraData) { |
199 | this.bytes.set(videocodecidBytes, this.position); | 199 | this.bytes.set(videocodecidBytes, this.position); |
200 | this.position += 12; | 200 | this.position += 12; |
201 | } else { | 201 | } else { |
202 | for (i in key) { | 202 | for (i = 0; i < key.length; i++) { |
203 | this.bytes[this.position] = key.charCodeAt(i); | 203 | this.bytes[this.position] = key.charCodeAt(i); |
204 | this.position++; | 204 | this.position++; |
205 | } | 205 | } |
... | @@ -223,7 +223,7 @@ hls.FlvTag = function(type, extraData) { | ... | @@ -223,7 +223,7 @@ hls.FlvTag = function(type, extraData) { |
223 | prepareWrite(this, 2); | 223 | prepareWrite(this, 2); |
224 | this.view.setUint16(this.position, key.length); | 224 | this.view.setUint16(this.position, key.length); |
225 | this.position += 2; | 225 | this.position += 2; |
226 | for (i in key) { | 226 | for (i = 0; i < key.length; i++) { |
227 | console.assert(key.charCodeAt(i) < 255); | 227 | console.assert(key.charCodeAt(i) < 255); |
228 | prepareWrite(this, 1); | 228 | prepareWrite(this, 1); |
229 | this.bytes[this.position] = key.charCodeAt(i); | 229 | this.bytes[this.position] = key.charCodeAt(i); | ... | ... |
-
Please register or sign in to post a comment