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:
parent
848a91dff7
commit
e4747b2344
1 changed files with 4 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (c) 2021 bleck9999
|
# Copyright (c) 2021 bleck9999
|
||||||
# https://github.com/bleck9999/ts-minifier
|
# https://github.com/bleck9999/ts-minifier
|
||||||
# Version: bf54a07d
|
# Version: 1095d14a
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import itertools
|
import itertools
|
||||||
|
@ -159,7 +159,7 @@ def minify(script: Code, userobjects, usages):
|
||||||
# equals and the whitespace needed for a definition
|
# 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
|
# 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"))
|
short_idents.pop(short_idents.index("if"))
|
||||||
mcode = script.rawcode
|
mcode = script.rawcode
|
||||||
aliases = []
|
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 "
|
print(f"{'Function' if otype == 'func' else 'Variable'} name {uo} could be shortened but no available "
|
||||||
f"names found (would save {uses} bytes)")
|
f"names found (would save {uses} bytes)")
|
||||||
continue
|
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
|
# 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)
|
# uses by anything as multiplying by a difference of 1 would be redundant)
|
||||||
if not auto_replace:
|
if not auto_replace:
|
||||||
|
@ -284,7 +284,7 @@ def minify(script: Code, userobjects, usages):
|
||||||
userobjects[minName] = "TIV"
|
userobjects[minName] = "TIV"
|
||||||
break
|
break
|
||||||
# the quotation marks are included in string
|
# 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:
|
if savings <= 0 or not auto_replace:
|
||||||
print(f"Not introducing variable for string {string} reused {uses} times (would save {savings} bytes)")
|
print(f"Not introducing variable for string {string} reused {uses} times (would save {savings} bytes)")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue