From 6c2423916b26e2d2e966ee79340aec07b29008d1 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Tue, 21 Nov 2023 00:41:19 +0000 Subject: [PATCH] Replace dictionary object with Map in Separate namespace for private vars in unmangled var name transform [perf] --- lib/serialize/varNames.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/serialize/varNames.js b/lib/serialize/varNames.js index dd08580f..18e5d8c9 100644 --- a/lib/serialize/varNames.js +++ b/lib/serialize/varNames.js @@ -92,7 +92,7 @@ const NAME_REGEX = /^(.*?)(?:\$(\d+))?$/; class UnmangledVarNameFactory extends VarNameFactory { constructor(reservedNames) { super(reservedNames); - this.used = Object.create(null); + this.used = new Map(); } transform(name, isPrivate) { @@ -100,8 +100,7 @@ class UnmangledVarNameFactory extends VarNameFactory { const [, nameWithoutPostfix, numStr] = name.match(NAME_REGEX); let num = numStr ? numStr * 1 : -1; - const {used} = this; - const usedNum = used[nameWithoutPostfix]; + const usedNum = this.used.get(nameWithoutPostfix); if (usedNum !== undefined && num <= usedNum) num = usedNum + 1; let outName = nameWithoutPostfix; @@ -111,7 +110,7 @@ class UnmangledVarNameFactory extends VarNameFactory { num++; } - used[nameWithoutPostfix] = num; + this.used.set(nameWithoutPostfix, num); return outName; }