1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-08 05:01:46 +00:00

maths is hard

This commit is contained in:
bleck9999 2021-08-20 18:15:24 +01:00
parent 848a91dff7
commit e4747b2344
No known key found for this signature in database
GPG key ID: D0CA0C41DB616843

View file

@ -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: