lua-users home
lua-l archive

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


On Thu, Jan 2, 2014 at 8:23 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> It works just like table keys. A hash code is computed from the
> string. Only if that is the same as a string already in the table (in
> which case the strings are likely to be equal) are the actual strings
> compared. O(#str) average speed.

It is worth reminding that this behavior changed in Lua 5.2. Now, only
"short" strings are interned. (By default, a "short string" is up to
40 bytes.)

-- Roberto


I hate to bring this subject back up after it sparked so much debate in the past, but I wonder if this limit could be increased to, say, 64 or 128 bytes? In my C libraries' __index and __newindex methods I avoid doing a lot of strcmp()s to compare the key to each valid field name, by storing all valid field names in a table in the registry. String interning means that instead of using strcmp() to check the key I can just use a standard equality test. But that will fail if I have a field with a more than 40-character name (not unimaginable) and Lua doesn't intern the string, meaning the pointer I get as my key isn't the same as the string I stored in the registry.

--
Sent from my Game Boy.