Skip to content

Commit

Permalink
Replace dictionary object with Map in Separate namespace for private …
Browse files Browse the repository at this point in the history
…vars in unmangled var name transform [perf]
  • Loading branch information
overlookmotel committed Nov 21, 2023
1 parent 9ec267f commit 6c24239
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/serialize/varNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,15 @@ const NAME_REGEX = /^(.*?)(?:\$(\d+))?$/;
class UnmangledVarNameFactory extends VarNameFactory {
constructor(reservedNames) {
super(reservedNames);
this.used = Object.create(null);
this.used = new Map();
}

transform(name, isPrivate) {
if (isPrivate) name = `${PRIVATE_PREFIX}${name}`;
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;
Expand All @@ -111,7 +110,7 @@ class UnmangledVarNameFactory extends VarNameFactory {
num++;
}

used[nameWithoutPostfix] = num;
this.used.set(nameWithoutPostfix, num);

return outName;
}
Expand Down

0 comments on commit 6c24239

Please sign in to comment.