1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-04 06:48:49 +02:00

perf: Use ES6 rest operator and allow V8 to optimize mergeOptions (#3743)

The current implementation causes the `mergeOptions` function to be
de-optimized. This change improves readability by switching to ES6
syntax AND it results in a roughly 75% improvement in the performance
of this function by transpiling to a `for` loop instead of
`slice.call`.
This commit is contained in:
Pat O'Neill 2016-11-04 14:19:50 -04:00 committed by Gary Katsevman
parent 6889e925b4
commit 5f42130b82

View File

@ -41,20 +41,17 @@ function customizer(destination, source) {
* provided objects
* @function mergeOptions
*/
export default function mergeOptions() {
// contruct the call dynamically to handle the variable number of
// objects to merge
const args = Array.prototype.slice.call(arguments);
export default function mergeOptions(...objects) {
// unshift an empty object into the front of the call as the target
// of the merge
args.unshift({});
objects.unshift({});
// customize conflict resolution to match our historical merge behavior
args.push(customizer);
objects.push(customizer);
merge.apply(null, args);
merge.apply(null, objects);
// return the mutated result object
return args[0];
return objects[0];
}