lua-users home
lua-l archive

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

On 26/06/2011 21:27, GrayFace wrote:
On 26.06.2011 8:35, Andre Leiradella wrote:

When writing bindings I usually get the key string in __index/__newindex metamethods and compute some hash with them which then I use in a switch. It would be nice if I could save the time spent in computing this hash since Lua already has one.

How about a table to map needed keys to switch indexes?

If you're suggesting using a Lua table, there's the lookup cost associated with retrieving the switch index. If you're suggesting using a hashtable other than Lua's, there's the cost if computing the hash *and* the lookup cost.

Like I said before, I already have a solution that is computing a hash of the string and using it in the switch. What I'm looking for is someway to use a hash that's already computed and save some cycles from my binding code.