From 43f0e45be89903bf5b301cfb55d5bd6ef128ffad Mon Sep 17 00:00:00 2001 From: Gorniaky Date: Thu, 20 Aug 2026 11:26:36 -0300 Subject: [PATCH] chore(prototypes): optimize getOrInsert and getOrInsertComputed methods --- src/@prototypes/map.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/@prototypes/map.ts b/src/@prototypes/map.ts index 40d4d20d..50e85d48 100644 --- a/src/@prototypes/map.ts +++ b/src/@prototypes/map.ts @@ -1,14 +1,12 @@ Map.prototype.getOrInsert ??= function (key, defaultValue) { - const value = this.get(key); - if (value !== undefined) return value; + if (this.has(key)) return this.get(key); this.set(key, defaultValue); return defaultValue; }; Map.prototype.getOrInsertComputed ??= function (key, callback) { - const value = this.get(key); - if (value !== undefined) return value; + if (this.has(key)) return this.get(key); const defaultValue = callback(key); this.set(key, defaultValue);