aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lstate.c2
-rw-r--r--lstring.c20
-rw-r--r--lstring.h3
-rw-r--r--ltests.c1
4 files changed, 6 insertions, 20 deletions
diff --git a/lstate.c b/lstate.c
index 76df6a20..42274292 100644
--- a/lstate.c
+++ b/lstate.c
@@ -76,7 +76,7 @@ static unsigned int luai_makeseed (lua_State *L) {
76 addbuff(buff, p, &h); /* local variable */ 76 addbuff(buff, p, &h); /* local variable */
77 addbuff(buff, p, &lua_newstate); /* public function */ 77 addbuff(buff, p, &lua_newstate); /* public function */
78 lua_assert(p == sizeof(buff)); 78 lua_assert(p == sizeof(buff));
79 return luaS_hash(buff, p, h, 1); 79 return luaS_hash(buff, p, h);
80} 80}
81 81
82#endif 82#endif
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) {
diff --git a/lstring.h b/lstring.h
index a413a9d3..450c2390 100644
--- a/lstring.h
+++ b/lstring.h
@@ -41,8 +41,7 @@
41#define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 41#define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b))
42 42
43 43
44LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, 44LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
45 unsigned int seed, size_t step);
46LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 45LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts);
47LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 46LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);
48LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 47LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
diff --git a/ltests.c b/ltests.c
index 99456159..7e3a389a 100644
--- a/ltests.c
+++ b/ltests.c
@@ -523,7 +523,6 @@ static lu_mem checkgraylist (global_State *g, GCObject *o) {
523 ((void)g); /* better to keep it available if we need to print an object */ 523 ((void)g); /* better to keep it available if we need to print an object */
524 while (o) { 524 while (o) {
525 lua_assert(!!isgray(o) ^ (getage(o) == G_TOUCHED2)); 525 lua_assert(!!isgray(o) ^ (getage(o) == G_TOUCHED2));
526 //lua_assert(isgray(o) || getage(o) == G_TOUCHED2);
527 lua_assert(!testbit(o->marked, TESTBIT)); 526 lua_assert(!testbit(o->marked, TESTBIT));
528 if (keepinvariant(g)) 527 if (keepinvariant(g))
529 l_setbit(o->marked, TESTBIT); /* mark that object is in a gray list */ 528 l_setbit(o->marked, TESTBIT); /* mark that object is in a gray list */