From 2db5ec5d366efbbf9e0838eabfa6be774a0518a0 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Tue, 13 Jul 2021 23:40:48 +0200 Subject: [PATCH] Improve memory usage when merging options --- source/core/options.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/core/options.ts b/source/core/options.ts index b74282025..05f963180 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -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); @@ -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') { @@ -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;