aemkei / jsfuck

Write any JavaScript with 6 Characters: []()!+
jsfuck.com
Do What The F*ck You Want To Public License
8.07k stars 671 forks source link

Optimize long strings #88

Closed hazzik closed 3 years ago

hazzik commented 5 years ago

The idea here goes like this: if a string has any unmapped characters it is practical to wrap the whole string into an escape sequence wrapper once instead of wrapping every single unmapped character.

This way we can save around 2000 symbols (as compared to the current master) per unmapped character except first one.

The only caveat here is that we need to escape \ and "in the original string otherwise the output will be corrupt. It turns out the most efficient way to do that is to convert these characters to escape sequences as well.

For example "XYZ" would be encoded as following:

Function("return\"\\130\\131\\132\"")() // 8298 chars

Instead of

Function("return\"\\u0058\"")() +
Function("return\"\\u0059\"")() +
Function("return\"\\u005a\"")() // 12134 chars
hazzik commented 4 years ago

@aemkei I think this is ready for review.

kamil-kielczewski commented 3 years ago

@hazzik - this repo/project is dead? I made some smal changes in readme.md - but I see that your pull request is here more than year... :(

aemkei commented 3 years ago

Sorry but I didn't looked into this. Hope to find some time and merge the open PRs. This one is has some conflicts now with other branches.

hazzik commented 3 years ago

@aemkei resolved

aemkei commented 3 years ago

Thanks for this! I was also thinking about having a simple wrapper that will put the final code into a sequence of escape sequences.