diff options
-rw-r--r-- | hash.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_hash="$Id: hash.c,v 2.18 1994/11/17 13:58:57 roberto Exp roberto $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.20 1994/11/25 19:27:03 roberto Exp $"; |
7 | 7 | ||
8 | #include "mem.h" | 8 | #include "mem.h" |
9 | #include "opcode.h" | 9 | #include "opcode.h" |
@@ -56,15 +56,15 @@ static int hashindex (Hash *t, Object *ref) /* hash function */ | |||
56 | return (((int)nvalue(ref))%nhash(t)); | 56 | return (((int)nvalue(ref))%nhash(t)); |
57 | case LUA_T_STRING: | 57 | case LUA_T_STRING: |
58 | { | 58 | { |
59 | int h; | 59 | unsigned long h = tsvalue(ref)->hash; |
60 | char *name = svalue(ref); | 60 | if (h == 0) |
61 | for (h=0; *name!=0; name++) /* interpret name as binary number */ | 61 | { |
62 | { | 62 | char *name = svalue(ref); |
63 | h <<= 8; | 63 | while (*name) |
64 | h += (unsigned char) *name; /* avoid sign extension */ | 64 | h = ((h<<5)-h)^(unsigned char)*(name++); |
65 | h %= nhash(t); /* make it a valid index */ | 65 | tsvalue(ref)->hash = h; |
66 | } | 66 | } |
67 | return h; | 67 | return h%nhash(t); /* make it a valid index */ |
68 | } | 68 | } |
69 | case LUA_T_FUNCTION: | 69 | case LUA_T_FUNCTION: |
70 | return (((int)bvalue(ref))%nhash(t)); | 70 | return (((int)bvalue(ref))%nhash(t)); |