lua-users home
lua-l archive

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



On Wed, Jan 14, 2015 at 12:31 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> [...] That said, a big +1 from me for removing those
> additional 4 bytes (from TString.hnext) in Lua 5.3 :)

I think we can do that following Tom's idea of storing the length of
short strings in a byte. Long strings are not hashed, so they do not
need the 'hnext' field. The struct could look like this:

typedef struct TString {
  CommonHeader;
  lu_byte extra;  /* reserved words for short strings; "has hash" for longs */
  lu_byte shtlen;  /* length for short strings */
  unsigned int hash;
  union {
    size_t len;  /* length for long string */
    struct TString *hnext;  /* linked list for hash (only for short strings) */
  } u;
} TString;
 

That looks like a very good solution to me.

Thanks,
Bogdan 
 
 
-- Roberto