lua-users home
lua-l archive

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


On Monday 12 December 2005 1:54 pm, Chris Marrin wrote:
> Thanks for the new solution! The problem with this, or any technique is
> that none of it is guaranteed. You are assuming the C compiler optimizes
> string constants from different modules to have the same address. C does
> not make this guarantee, just like Lua does not make the guarantee that
> a string returned from lua_tostring() will never change. And this

if you strive for full compiler portability, a best strategy would be to store 
a small integer (from an enum) in the table, instead of the (const char *).

> technique requires two table lookups to get the string pointer. It seems
> unlikely that this would be faster than a strcmp() or other string

the advantage is that you can do those two table lookups once, and then 
compare the result with several pointers.  this scales much better as the 
number of possible targets grows.

of course, even better than many pointer comparisons is a switch(){...} 
statement, using enums (the code generated by a switch(){..} looks like a 
precomputed hash table with jump offsets, very scalable)

-- 
Javier

Attachment: pgplg2mVcUvoN.pgp
Description: PGP signature