lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 03.05.2014 12:59 schröbte Coroutines:
1) I'd like to see `a` (note the backticks) be a run-once form of
string.byte('a') -- a single-character transform that happens at
compile-time.  When you use string.byte() in a loop it'll be run every
time, and I argue that creating a local for this purpose is difficult
to name and largely a waste of a local.

2) I'd like the __index of the string type to change so if called with
a numeric key it'll do this [essentially] in a C function:  ('cat')[3]
-> string.byte('cat', 3, 3)  This could be done more cheaply in C than
with the additional call overhead of a string.byte() in Lua for
tight/large loops.

It's very costly to create a lot of single-character Lua strings that
get hashed and then quickly discarded after a comparison -- this is
what I've come up with to help:

We already have long strings and short strings in Lua 5.2. What about an unhashed "very short" string (7 bytes plus NUL byte) that lives directly in a TValue? It should get rid of the hashing overhead for single character strings (not sure how much hashing there is for single-byte strings), but not the call overhead of string.byte, though ...

(At the moment there is a requirement that keywords are hashed strings. Not sure why, and whether this would make this proposal complicated ...)

Philipp