tiny code refactoring in 'luaS_hash'

This commit is contained in:
Roberto Ierusalimschy 2015-11-23 09:32:51 -02:00
parent 3feb702df8
commit f230898ad6
1 changed files with 3 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lstring.c,v 2.54 2015/10/08 15:53:31 roberto Exp roberto $
** $Id: lstring.c,v 2.55 2015/11/03 15:36:01 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@ -48,10 +48,9 @@ int luaS_eqlngstr (TString *a, TString *b) {
unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {
unsigned int h = seed ^ cast(unsigned int, l);
size_t l1;
size_t step = (l >> LUAI_HASHLIMIT) + 1;
for (l1 = l; l1 >= step; l1 -= step)
h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1]));
for (; l >= step; l -= step)
h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));
return h;
}