lua-users home
lua-l archive

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


On Thu, Jan 19, 2012 at 13:39, John Graham-Cumming <jgc@jgc.org> wrote:
2. Don't hash large strings.  In this situation a value of 128 bytes can be counted as large.  Any strings above this can be stored in a simple GCObject** list.  The hash value of the large strings (which may be needed if the string is to be inserted into a table) could just be a random 32 bit number.  Given that eqstr assumes the same pointer for the same string a different operation would need to be defined is 
len(string)>128.

Actually the right thing to do is have a 0 hash value for these strings and then when the string is actually used in a table by a Lua programmer hash the entire string to get its value.  That way the security of the system is protected (because a randomized hash of the full string is used), but the performance is still good as the hashing is delayed until needed.

John.