Skip to content

Commit c356169

Browse files
author
Alvaro Velad
committed
fix(dash): Fix performance regression
1 parent 89409ce commit c356169

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

lib/dash/dash_parser.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ goog.require('shaka.text.TextEngine');
2222
goog.require('shaka.util.CmcdManager');
2323
goog.require('shaka.util.Error');
2424
goog.require('shaka.util.Functional');
25-
goog.require('shaka.util.Iterables');
2625
goog.require('shaka.util.LanguageUtils');
2726
goog.require('shaka.util.ManifestParserUtils');
2827
goog.require('shaka.util.MimeUtils');
@@ -104,7 +103,7 @@ shaka.dash.DashParser = class {
104103

105104
/**
106105
* Period IDs seen in previous manifest.
107-
* @private {!Array.<number>}
106+
* @private {!Array.<string>}
108107
*/
109108
this.lastManifestUpdatePeriodIds_ = [];
110109

@@ -556,10 +555,9 @@ shaka.dash.DashParser = class {
556555
const periods = [];
557556
let prevEnd = 0;
558557
const periodNodes = XmlUtils.findChildren(mpd, 'Period');
559-
// This uses a for-loop rather than a for-of loop because this needs to look
560-
// ahead to the next element.
561-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
562-
for (const {i, item: elem, next} of enumerate(periodNodes)) {
558+
for (let i = 0; i < periodNodes.length; i++) {
559+
const elem = periodNodes[i];
560+
const next = periodNodes[i + 1];
563561
const start = /** @type {number} */ (
564562
XmlUtils.parseAttr(elem, 'start', XmlUtils.parseDuration, prevEnd));
565563
const periodId = elem.id;

lib/dash/mpd_utils.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ goog.require('shaka.net.NetworkingEngine');
1212
goog.require('shaka.util.AbortableOperation');
1313
goog.require('shaka.util.Error');
1414
goog.require('shaka.util.Functional');
15-
goog.require('shaka.util.Iterables');
1615
goog.require('shaka.util.ManifestParserUtils');
1716
goog.require('shaka.util.XmlUtils');
1817
goog.requireType('shaka.dash.DashParser');
@@ -142,8 +141,9 @@ shaka.dash.MpdUtils = class {
142141
const timeline = [];
143142
let lastEndTime = -unscaledPresentationTimeOffset;
144143

145-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
146-
for (const {item: timePoint, next} of enumerate(timePoints)) {
144+
for (let i = 0; i < timePoints.length; ++i) {
145+
const timePoint = timePoints[i];
146+
const next = timePoints[i + 1];
147147
let t = XmlUtils.parseAttr(timePoint, 't', XmlUtils.parseNonNegativeInt);
148148
const d =
149149
XmlUtils.parseAttr(timePoint, 'd', XmlUtils.parseNonNegativeInt);
@@ -225,8 +225,7 @@ shaka.dash.MpdUtils = class {
225225
timeline[timeline.length - 1].end = startTime / timescale;
226226
}
227227

228-
for (const _ of shaka.util.Iterables.range(repeat + 1)) {
229-
shaka.util.Functional.ignored(_);
228+
for (let j = 0; j <= repeat; ++j) {
230229
const endTime = startTime + d;
231230
const item = {
232231
start: startTime / timescale,

lib/dash/segment_template.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ goog.require('shaka.media.InitSegmentReference');
1414
goog.require('shaka.media.SegmentIndex');
1515
goog.require('shaka.media.SegmentReference');
1616
goog.require('shaka.util.Error');
17-
goog.require('shaka.util.Iterables');
1817
goog.require('shaka.util.ManifestParserUtils');
1918
goog.require('shaka.util.ObjectUtils');
2019
goog.requireType('shaka.dash.DashParser');
@@ -504,8 +503,9 @@ shaka.dash.SegmentTemplate = class {
504503

505504
/** @type {!Array.<!shaka.media.SegmentReference>} */
506505
const references = [];
507-
const enum_ = (it) => shaka.util.Iterables.enumerate(it);
508-
for (const {i, item: {start, unscaledStart, end}} of enum_(info.timeline)) {
506+
for (let i = 0; i < info.timeline.length; i++) {
507+
const {start, unscaledStart, end} = info.timeline[i];
508+
509509
// Note: i = k - 1, where k indicates the k'th segment listed in the MPD.
510510
// (See section 5.3.9.5.3 of the DASH spec.)
511511
const segmentReplacement = i + info.startNumber;

lib/util/string_utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ shaka.util.StringUtils = class {
158158
static toUTF16(str, littleEndian) {
159159
const result = new ArrayBuffer(str.length * 2);
160160
const view = new DataView(result);
161-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
162-
for (const {i, item} of enumerate(str)) {
163-
const value = item.charCodeAt(0);
161+
for (let i = 0; i < str.length; ++i) {
162+
const value = str.charCodeAt(i);
164163
view.setUint16(/* position= */ i * 2, value, littleEndian);
165164
}
166165
return result;

lib/util/uint8array_utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ shaka.util.Uint8ArrayUtils = class {
7474
// byte.
7575
const bytes = window.atob(str.replace(/-/g, '+').replace(/_/g, '/'));
7676
const result = new Uint8Array(bytes.length);
77-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
78-
for (const {i, item} of enumerate(bytes)) {
79-
result[i] = item.charCodeAt(0);
77+
for (let i = 0; i < bytes.length; ++i) {
78+
result[i] = bytes.charCodeAt(i);
8079
}
8180
return result;
8281
}

0 commit comments

Comments
 (0)