|
Flyer31 Test:
While this could be an optimization that PUC-Lua could implement, it is only implemented in LuaJIT and only in the JIT. Further, it is not trivial since substrings normally need a copy since a null character needs to be appended for the C API, however, this could be postponed until the string is used in the C API. Luckily, when using string.sub for strings of length 1 it is very likely that the string is already in the short string table used by Lua to reuse short strings.Oh, very helpful and impressive info is this, thank you very much ... . On Wed, Sep 15, 2021 at 5:56 PM Philippe Verdy <verdyp@gmail.com> wrote:String:sub dues not need to allocate anything, it uses shared buffers, because all strings are immutable. The collector just needs to handle the main string wgre all references to its substrings should be counted. Garbage collection *may* occur only for concatenations.
Regards, Xmilia