lua-users home
lua-l archive

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


> I tried it, and the running time of the test code reduce to zero second.
> I think maybe this is more adaptable to various situations if lua code change like that.

Maybe a slightly better option would be this one:

#define hashint(t,i)  \
  hashmod(t, cast_uint(l_castS2U(i) & (~0u)) ^ \
             cast_uint(l_castS2U(i) >> (sizeof(int) * 8 - 8) >> 8));

It uses an unsigned 32-bit division, which is cheaper than an unsigned
64-bit division. (If lua_Integer == int, the compiler should be able
to optimize this out.)

-- Roberto