From e4747b2344665c733112e2c08aa5adc008fe4df9 Mon Sep 17 00:00:00 2001 From: bleck9999 <55853712+bleck9999@users.noreply.github.com> Date: Fri, 20 Aug 2021 18:15:24 +0100 Subject: [PATCH] maths is hard --- ts-minifier.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ts-minifier.py b/ts-minifier.py index c696424..0340f10 100644 --- a/ts-minifier.py +++ b/ts-minifier.py @@ -1,6 +1,6 @@ # Copyright (c) 2021 bleck9999 # https://github.com/bleck9999/ts-minifier -# Version: bf54a07d +# Version: 1095d14a import argparse import itertools @@ -159,7 +159,7 @@ def minify(script: Code, userobjects, usages): # equals and the whitespace needed for a definition # # obviously for a rename you're already defining it so it's just the difference between lengths multiplied by uses - short_idents = [x for x in (ascii_letters+'_')] + [x[0]+x[1] for x in itertools.permutations(ascii_letters+'_', 2)] + short_idents = [x for x in (ascii_letters+'_')] + [x[0]+x[1] for x in itertools.product(ascii_letters+'_', repeat=2)] short_idents.pop(short_idents.index("if")) mcode = script.rawcode aliases = [] @@ -184,7 +184,7 @@ def minify(script: Code, userobjects, usages): print(f"{'Function' if otype == 'func' else 'Variable'} name {uo} could be shortened but no available " f"names found (would save {uses} bytes)") continue - # we assume that nobody is insane enough to exhaust all *2,756* 2 character names, + # we assume that nobody is insane enough to exhaust all *2,808* 2 character names, # instead that uo is len 2 and all the 1 character names are in use (because of that we dont multiply # uses by anything as multiplying by a difference of 1 would be redundant) if not auto_replace: @@ -284,7 +284,7 @@ def minify(script: Code, userobjects, usages): userobjects[minName] = "TIV" break # the quotation marks are included in string - savings = uses * len(string) - (len(string) + len(minName) + 1) + savings = uses * len(string) - (len(string) + len(minName) + 2) if savings <= 0 or not auto_replace: print(f"Not introducing variable for string {string} reused {uses} times (would save {savings} bytes)") else: