Skip to content

Commit 6627468

Browse files
TheModMakerAnteWall
authored andcommitted
Add utility for looping from 0 to n.
Closes shaka-project#1518 Change-Id: I865f7a0311516d04ae84532dab873e1aaa31eb24
1 parent 6b1010c commit 6627468

26 files changed

+89
-70
lines changed

build/misspellings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
r'(?i)arti?fi?ci?ai?l': 'artificial',
66
r'(?i)cur+ent': 'current',
77
r'(?i)ful+screen': 'fullscreen',
8+
r'(?i)interable': 'iterable',
89
r'(?i)int(er|re)p(er|er)tation': 'interpretation',
910
r'(?i)langauge': 'language',
1011
r'(?i)mananger': 'manager',

lib/dash/mpd_utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ shaka.dash.MpdUtils = class {
233233
timeline[timeline.length - 1].end = startTime / timescale;
234234
}
235235

236-
for (let j = 0; j <= repeat; ++j) {
236+
for (const _ of shaka.util.Iterables.range(repeat + 1)) {
237+
shaka.util.Functional.ignored(_);
237238
const endTime = startTime + d;
238239
const item = {
239240
start: startTime / timescale,

lib/dash/segment_list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ goog.require('shaka.media.SegmentIndex');
2525
goog.require('shaka.media.SegmentReference');
2626
goog.require('shaka.util.Error');
2727
goog.require('shaka.util.Functional');
28+
goog.require('shaka.util.Iterables');
2829
goog.require('shaka.util.ManifestParserUtils');
2930
goog.require('shaka.util.XmlUtils');
3031

@@ -212,7 +213,7 @@ shaka.dash.SegmentList = class {
212213
/** @type {!Array.<!shaka.media.SegmentReference>} */
213214
const references = [];
214215
let prevEndTime = info.startTime;
215-
for (let i = 0; i < max; i++) {
216+
for (const i of shaka.util.Iterables.range(max)) {
216217
const segment = info.mediaSegments[i];
217218
const mediaUri = ManifestParserUtils.resolveUris(
218219
baseUris, [segment.mediaUri]);

lib/media/adaptation_set.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
goog.provide('shaka.media.AdaptationSet');
1919

2020
goog.require('goog.asserts');
21+
goog.require('shaka.util.Iterables');
2122
goog.require('shaka.util.MimeUtils');
2223

2324

@@ -219,7 +220,7 @@ shaka.media.AdaptationSet = class {
219220
codecsA.sort();
220221
codecsB.sort();
221222

222-
for (let i = 0; i < codecsA.length; i++) {
223+
for (const i of shaka.util.Iterables.range(codecsA.length)) {
223224
if (codecsA[i] != codecsB[i]) {
224225
return false;
225226
}

lib/media/mp4_segment_index_parser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ goog.require('goog.asserts');
2121
goog.require('shaka.log');
2222
goog.require('shaka.media.SegmentReference');
2323
goog.require('shaka.util.Error');
24+
goog.require('shaka.util.Iterables');
2425
goog.require('shaka.util.Mp4Parser');
2526

2627

@@ -123,7 +124,8 @@ shaka.media.Mp4SegmentIndexParser = class {
123124
let unscaledStartTime = earliestPresentationTime;
124125
let startByte = sidxOffset + box.size + firstOffset;
125126

126-
for (let i = 0; i < referenceCount; i++) {
127+
for (const _ of shaka.util.Iterables.range(referenceCount)) {
128+
shaka.util.Functional.ignored(_);
127129
// |chunk| is 1 bit for |referenceType|, and 31 bits for |referenceSize|.
128130
const chunk = box.reader.readUint32();
129131
const referenceType = (chunk & 0x80000000) >>> 31;

lib/media/streaming_engine.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ shaka.media.StreamingEngine = class {
20042004
}
20052005

20062006
// Now setup all known Periods.
2007-
for (let i = 0; i < this.manifest_.periods.length; ++i) {
2007+
for (const i of shaka.util.Iterables.range(this.manifest_.periods.length)) {
20082008
this.setupPeriod_(i).catch(Functional.noop);
20092009
}
20102010

lib/media/time_ranges_utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
goog.provide('shaka.media.TimeRangesUtils');
1919

20+
goog.require('shaka.util.Iterables');
2021
goog.require('shaka.util.Platform');
2122

2223

@@ -181,7 +182,7 @@ shaka.media.TimeRangesUtils = class {
181182
return [];
182183
}
183184
const ret = [];
184-
for (let i = 0; i < b.length; i++) {
185+
for (const i of shaka.util.Iterables.range(b.length)) {
185186
ret.push({start: b.start(i), end: b.end(i)});
186187
}
187188
return ret;

lib/text/mp4_vtt_parser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ goog.require('shaka.text.VttTextParser');
2525
goog.require('shaka.util.DataViewReader');
2626
goog.require('shaka.util.Error');
2727
goog.require('shaka.util.Functional');
28+
goog.require('shaka.util.Iterables');
2829
goog.require('shaka.util.Mp4Parser');
2930
goog.require('shaka.util.StringUtils');
3031
goog.require('shaka.util.TextParser');
@@ -299,7 +300,8 @@ shaka.text.Mp4VttParser = class {
299300

300301
const samples = [];
301302

302-
for (let sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) {
303+
for (const _ of shaka.util.Iterables.range(sampleCount)) {
304+
shaka.util.Functional.ignored(_);
303305
/** @type {shaka.text.Mp4VttParser.TimeSegment} */
304306
const sample = {
305307
duration: null,

lib/util/ebml_parser.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,8 @@ shaka.util.EbmlParser = class {
144144
goog.asserts.assert(numBytes <= 8 && numBytes >= 1, 'Incorrect log2 value');
145145

146146
const vint = new Uint8Array(numBytes);
147-
vint[0] = firstByte;
148-
149-
// Include the remaining bytes.
150-
for (let i = 1; i < numBytes; i++) {
151-
vint[i] = this.reader_.readUint8();
147+
for (const i of shaka.util.Iterables.range(numBytes)) {
148+
vint[i] = i == 0 ? firstByte : this.reader_.readUint8();
152149
}
153150

154151
return vint;
@@ -292,7 +289,7 @@ shaka.util.EbmlElement = class {
292289

293290
let value = 0;
294291

295-
for (let i = 0; i < this.dataView_.byteLength; i++) {
292+
for (const i of shaka.util.Iterables.range(this.dataView_.byteLength)) {
296293
const chunk = this.dataView_.getUint8(i);
297294
value = (256 * value) + chunk;
298295
}

lib/util/functional.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ shaka.util.Functional = class {
5454
return all.concat(part);
5555
}
5656

57+
/**
58+
* A no-op function that ignores its arguments. This is used to suppress
59+
* unused variable errors.
60+
* @param {...*} args
61+
*/
62+
static ignored(...args) {}
63+
5764

5865
/**
5966
* A no-op function. Useful in promise chains.

0 commit comments

Comments
 (0)