[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: A useful useless fact about Lua keywords
- From: Xmilia Hermit <xmilia.hermit@...>
- Date: Wed, 15 Sep 2021 19:04:10 +0200
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 <firstname.lastname@example.org> 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.