From f6431302544d8c10a44d339c0ef2a120d56a671b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20Hano=C4=9Flu?= Date: Thu, 21 Nov 2024 18:51:14 +0300 Subject: [PATCH] refactor: Minor optimization --- src/merge.ts | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/merge.ts b/src/merge.ts index 57bf6f7..e8ca871 100644 --- a/src/merge.ts +++ b/src/merge.ts @@ -80,30 +80,26 @@ export function merge( const functionCache = new Map(); export function getMergeFunction(options?: merge.Options): Function { - const f = option => - option == null - ? 'n' - : typeof option === 'function' - ? 'f' - : option - ? '1' - : '0'; - const cacheKey = - f(options?.deep) + - ',' + - f(options?.moveArrays) + - ',' + - f(options?.keepExisting) + - ',' + - f(options?.copyDescriptors) + - ',' + - f(options?.ignore) + - ',' + - f(options?.ignoreUndefined) + - ',' + - f(options?.ignoreNulls) + - ',' + - f(options?.filter); + const cacheKey = [ + options?.deep, + options?.moveArrays, + options?.keepExisting, + options?.copyDescriptors, + options?.ignore, + options?.ignoreUndefined, + options?.ignoreNulls, + options?.filter, + ] + .map(option => + option == null + ? 'n' + : typeof option === 'function' + ? 'f' + : option + ? '1' + : '0', + ) + .join(); let fn = functionCache.get(cacheKey); if (!fn) { fn = buildMerge(options);