diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-23 09:32:51 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-23 09:32:51 -0200 |
commit | f230898ad6f1d3fd1bc0216b2f4a504db112f2df (patch) | |
tree | a40481a12ff34376929dc73a0a9f9a55800d9d1d /lstring.c | |
parent | 3feb702df8b362d3d3a4bdeda48313da1278ebe4 (diff) | |
download | lua-f230898ad6f1d3fd1bc0216b2f4a504db112f2df.tar.gz lua-f230898ad6f1d3fd1bc0216b2f4a504db112f2df.tar.bz2 lua-f230898ad6f1d3fd1bc0216b2f4a504db112f2df.zip |
tiny code refactoring in 'luaS_hash'
Diffstat (limited to 'lstring.c')
-rw-r--r-- | lstring.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 2.54 2015/10/08 15:53:31 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.55 2015/11/03 15:36:01 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -48,10 +48,9 @@ int luaS_eqlngstr (TString *a, TString *b) { | |||
48 | 48 | ||
49 | unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) { | 49 | unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) { |
50 | unsigned int h = seed ^ cast(unsigned int, l); | 50 | unsigned int h = seed ^ cast(unsigned int, l); |
51 | size_t l1; | ||
52 | size_t step = (l >> LUAI_HASHLIMIT) + 1; | 51 | size_t step = (l >> LUAI_HASHLIMIT) + 1; |
53 | for (l1 = l; l1 >= step; l1 -= step) | 52 | for (; l >= step; l -= step) |
54 | h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1])); | 53 | h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1])); |
55 | return h; | 54 | return h; |
56 | } | 55 | } |
57 | 56 | ||