Skip to content

Commit

Permalink
perf: Optimization to resolve uris (#5657)
Browse files Browse the repository at this point in the history
Chained use of maps and reduce on legacy devices reduces performance. So
if there is only one url to generate we can optimize performance.
  • Loading branch information
avelad authored and joeyparrish committed Sep 14, 2023
1 parent 7df352d commit 971b2a0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/util/manifest_parser_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ shaka.util.ManifestParserUtils = class {
return baseUris;
}

if (baseUris.length == 1 && relativeUris.length == 1) {
const baseUri = new goog.Uri(baseUris[0]);
const relativeUri = new goog.Uri(relativeUris[0]);
return [baseUri.resolve(relativeUri).toString()];
}

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) => new goog.Uri(uri))
.map((base) => relativeAsGoog.map((i) => base.resolve(i)))
.reduce(Functional.collapseArrays, [])
.map((uri) => uri.toString());
return baseUris.map((uri) => {
const base = new goog.Uri(uri);
return relativeAsGoog.map((i) => base.resolve(i).toString());
}).reduce(Functional.collapseArrays, []);
}


Expand Down

0 comments on commit 971b2a0

Please sign in to comment.