[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: proposal for reading individual characters from strings faster
- From: Tim Hill <drtimhill@...>
- Date: Sat, 3 May 2014 13:04:50 -0700
On May 3, 2014, at 12:29 PM, Coroutines <coroutines@gmail.com> wrote:
> On Sat, May 3, 2014 at 11:27 AM, Tim Hill <drtimhill@gmail.com> wrote:
>
>> One thing to remember is that compile time is not “free”, since in many environments Lua source is compiled JIT. In some of our applications code fragments are compiled, run once, and discarded. This makes compile time easily 50% of the total run time and is only feasible because the Lua compiler is so efficient.
>
> I agree with you, I don't know the scope of what could prevent this --
> I just wanted `a` evaluated once at compile time :-)
>
And in fact I agree that the back-quote syntax (or some equivalent) would have very little impact on compiler size or speed. I’m just nor sure about some of the other @string.byte() stuff, which starts to look a bit “heroic”.
However, no “simple” feature comes without hidden costs. The back-quote syntax appears to isolate source code from character coding issues, but does it? One approach is to always assume UTF-8 encoding, which is consistent across platforms, but may differ from the local encoding. This means that `a` ~= string.byte(“a”) on (say) EBCDIC platforms. Another approach is to use the local platform encoding, but this also doesn’t work since the locale at compile time may differ from the locale at run-time (even if the code is run directly after compile).
So what you end up with is `a` being a compile-time shorthand for utf8.codepoint(“a”), which really doesn’t buy you much over calling the function and storing the code point in a local.
—Tim