Skip to content

Commit

Permalink
Improve memory usage when merging options
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Jul 13, 2021
1 parent 099bbfe commit 2db5ec5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion source/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,6 @@ export default class Options {

init(this, options, this);
init(options, options, this);
this._init.push(options);

// This is way much faster than cloning ^_^
Object.freeze(options);
Expand All @@ -846,6 +845,8 @@ export default class Options {
this._merging = true;

try {
let push = false;

for (const key in options) {
// `got.extend()` options
if (key === 'mutableDefaults' || key === 'handlers') {
Expand All @@ -863,6 +864,12 @@ export default class Options {

// @ts-expect-error Type 'unknown' is not assignable to type 'never'.
this[key as keyof Options] = options[key as keyof Options];

push = true;
}

if (push) {
this._init.push(options);
}
} finally {
this._merging = false;
Expand Down

0 comments on commit 2db5ec5

Please sign in to comment.