Skip to content

Commit

Permalink
perf(manifest): avoid unnecessary looping in uri resolver (#5773)
Browse files Browse the repository at this point in the history
This removes creating an array of arrays in manifest URI resolver and
uses a nested loop to update an empty array instead

Co-authored-by: Ivan Kohut <ivan.kohut@lamin.ar>
  • Loading branch information
2 people authored and joeyparrish committed Feb 17, 2024
1 parent da38819 commit b887978
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/util/manifest_parser_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ goog.provide('shaka.util.ManifestParserUtils');

goog.require('goog.Uri');
goog.require('shaka.util.Error');
goog.require('shaka.util.Functional');


/**
Expand All @@ -24,7 +23,6 @@ shaka.util.ManifestParserUtils = class {
* @return {!Array.<string>}
*/
static resolveUris(baseUris, relativeUris) {
const Functional = shaka.util.Functional;
if (relativeUris.length == 0) {
return baseUris;
}
Expand All @@ -36,12 +34,18 @@ shaka.util.ManifestParserUtils = class {
}

const relativeAsGoog = relativeUris.map((uri) => new goog.Uri(uri));
// Resolve each URI relative to each base URI, creating an Array of Arrays.
// Then flatten the Arrays into a single Array.
return baseUris.map((uri) => {
const base = new goog.Uri(uri);
return relativeAsGoog.map((i) => base.resolve(i).toString());
}).reduce(Functional.collapseArrays, []);

// For each base URI, this code resolves it with every relative URI.
// The result is a single array containing all the resolved URIs.
const resolvedUris = [];
for (const baseStr of baseUris) {
const base = new goog.Uri(baseStr);
for (const relative of relativeAsGoog) {
resolvedUris.push(base.resolve(relative).toString());
}
}

return resolvedUris;
}


Expand Down

0 comments on commit b887978

Please sign in to comment.