From 689f8f504d03d47f184c45c85d0b3eb597fafe85 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 11 May 2021 16:41:32 +0100 Subject: enhance `mangle` (#4926) --- lib/scope.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/scope.js b/lib/scope.js index f0d4c921..bb36583c 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -800,6 +800,7 @@ var base54 = (function() { var leading = init("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_"); var chars, frequency; function reset() { + chars = null; frequency = Object.create(freq); } base54.consider = function(str, delta) { @@ -811,19 +812,15 @@ var base54 = (function() { return frequency[b] - frequency[a]; } base54.sort = function() { - chars = leading.sort(compare).concat(digits.sort(compare)); + chars = leading.sort(compare).concat(digits).sort(compare); }; base54.reset = reset; reset(); function base54(num) { - var ret = "", base = 54; - num++; - do { - num--; - ret += chars[num % base]; - num = Math.floor(num / base); - base = 64; - } while (num > 0); + var ret = leading[num % 54]; + for (num = Math.floor(num / 54); --num >= 0; num >>= 6) { + ret += chars[num & 0x3F]; + } return ret; } return base54; -- cgit v1.2.3