LytixDev / slash

The Slash Scripting Language
GNU General Public License v3.0
7 stars 0 forks source link

enhance: static string optimisation #114

Open LytixDev opened 4 months ago

LytixDev commented 4 months ago

In the lexer, strings are now stored on an arena and are NULL terminated. Once the string is evaluated in the interpreter, the string is copied and GC allocated. For static strings, we can omit the copying and instead simply store a pointer to the arena containing the string. Since strings are immutable, this works out nicely.

It is important that the arena storing the strings are not cleared during the entire lifetime of a slash program. Currently, the arena used is the ast_arena which is reset after each run of the interpreter. A solution could be to create a StringArena or something which is never reset during a programs lifetime.