lua-users home
lua-l archive

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

On 2017-10-15 02:58 PM, Dirk Laurie wrote:
2017-10-15 17:43 GMT+02:00 Soni L. <>:
I'm reading the Lua code, and it seems that Lua always checks the hash part,
even for tables that don't use it. Why is this?
That's not how I read the code. Here are the comments and return
statements of luaH_next.

   /* find original element */
   /* try first array part */
   /* a non-nil value? */
       return 1;
   /* hash part */
   /* a non-nil value? */
       return 1;
   return 0;  /* no more elements */

It's quite possible to return without reaching the code dealing with
the hash part.

Look at luaH_get. e.g. t[1] always checks hash part which does have a cost. the only way to avoid that cost is to fill the array part: if you have 256 possible values, you need to fill t[1] to t[256]. and ofc t[0] always goes to the hash part so you also need to shift by one if 0 is a valid index.

Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.