aboutsummaryrefslogtreecommitdiff
path: root/lstring.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstring.c')
-rw-r--r--lstring.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/lstring.c b/lstring.c
index 6f157473..138871c7 100644
--- a/lstring.c
+++ b/lstring.c
@@ -23,16 +23,6 @@
23 23
24 24
25/* 25/*
26** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a long string to
27** compute its hash
28*/
29#if !defined(LUAI_HASHLIMIT)
30#define LUAI_HASHLIMIT 5
31#endif
32
33
34
35/*
36** Maximum size for string table. 26** Maximum size for string table.
37*/ 27*/
38#define MAXSTRTB cast_int(luaM_limitN(MAX_INT, TString*)) 28#define MAXSTRTB cast_int(luaM_limitN(MAX_INT, TString*))
@@ -50,10 +40,9 @@ int luaS_eqlngstr (TString *a, TString *b) {
50} 40}
51 41
52 42
53unsigned int luaS_hash (const char *str, size_t l, unsigned int seed, 43unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {
54 size_t step) {
55 unsigned int h = seed ^ cast_uint(l); 44 unsigned int h = seed ^ cast_uint(l);
56 for (; l >= step; l -= step) 45 for (; l > 0; l--)
57 h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1])); 46 h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));
58 return h; 47 return h;
59} 48}
@@ -63,8 +52,7 @@ unsigned int luaS_hashlongstr (TString *ts) {
63 lua_assert(ts->tt == LUA_VLNGSTR); 52 lua_assert(ts->tt == LUA_VLNGSTR);
64 if (ts->extra == 0) { /* no hash? */ 53 if (ts->extra == 0) { /* no hash? */
65 size_t len = ts->u.lnglen; 54 size_t len = ts->u.lnglen;
66 size_t step = (len >> LUAI_HASHLIMIT) + 1; 55 ts->hash = luaS_hash(getstr(ts), len, ts->hash);
67 ts->hash = luaS_hash(getstr(ts), len, ts->hash, step);
68 ts->extra = 1; /* now it has its hash */ 56 ts->extra = 1; /* now it has its hash */
69 } 57 }
70 return ts->hash; 58 return ts->hash;
@@ -201,7 +189,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) {
201 TString *ts; 189 TString *ts;
202 global_State *g = G(L); 190 global_State *g = G(L);
203 stringtable *tb = &g->strt; 191 stringtable *tb = &g->strt;
204 unsigned int h = luaS_hash(str, l, g->seed, 1); 192 unsigned int h = luaS_hash(str, l, g->seed);
205 TString **list = &tb->hash[lmod(h, tb->size)]; 193 TString **list = &tb->hash[lmod(h, tb->size)];
206 lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */ 194 lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */
207 for (ts = *list; ts != NULL; ts = ts->u.hnext) { 195 for (ts = *list; ts != NULL; ts = ts->u.hnext) {