5 ms·
Strings are interned in Lua which means identical strings have the same reference.
by sgolestane 13y ago
Strings are interned in Lua which means identical strings have the same reference.
- StavrosK 13y agoThat's interesting... Would interning change the speed at which strings are generated, then?
- daurnimator 13y agoYes, strings are hashed at creation time. This means strings can never be modified => a new one is created. The down side is that string modification (including appending) in a loop is expensive.
- russellsprouts 13y agoOf course, languages like Java have StringBuffer objects. In Lua, if you are generating a string, and you know that it will need a lot of concatenations, you can use something like this: local string_buffer = {} while condition() do table.insert(string_buffer, getString()) end local string = table.concat(string_buffer)