diff options
Diffstat (limited to 'lstring.c')
-rw-r--r-- | lstring.c | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.75 2002/08/16 14:45:55 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.76 2002/08/30 19:09:21 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 | */ |
@@ -32,7 +32,7 @@ void luaS_resize (lua_State *L, int newsize) { | |||
32 | GCObject *p = tb->hash[i]; | 32 | GCObject *p = tb->hash[i]; |
33 | while (p) { /* for each node in the list */ | 33 | while (p) { /* for each node in the list */ |
34 | GCObject *next = p->gch.next; /* save next */ | 34 | GCObject *next = p->gch.next; /* save next */ |
35 | lu_hash h = (&p->ts)->tsv.hash; | 35 | lu_hash h = gcotots(p)->tsv.hash; |
36 | int h1 = lmod(h, newsize); /* new position */ | 36 | int h1 = lmod(h, newsize); /* new position */ |
37 | lua_assert(cast(int, h%newsize) == lmod(h, newsize)); | 37 | lua_assert(cast(int, h%newsize) == lmod(h, newsize)); |
38 | p->gch.next = newhash[h1]; /* chain it */ | 38 | p->gch.next = newhash[h1]; /* chain it */ |
@@ -59,7 +59,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) { | |||
59 | tb = &G(L)->strt; | 59 | tb = &G(L)->strt; |
60 | h = lmod(h, tb->size); | 60 | h = lmod(h, tb->size); |
61 | ts->tsv.next = tb->hash[h]; /* chain new entry */ | 61 | ts->tsv.next = tb->hash[h]; /* chain new entry */ |
62 | tb->hash[h] = cast(GCObject *, ts); | 62 | tb->hash[h] = valtogco(ts); |
63 | tb->nuse++; | 63 | tb->nuse++; |
64 | if (tb->nuse > cast(ls_nstr, tb->size) && tb->size <= MAX_INT/2) | 64 | if (tb->nuse > cast(ls_nstr, tb->size) && tb->size <= MAX_INT/2) |
65 | luaS_resize(L, tb->size*2); /* too crowded */ | 65 | luaS_resize(L, tb->size*2); /* too crowded */ |
@@ -68,17 +68,18 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) { | |||
68 | 68 | ||
69 | 69 | ||
70 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | 70 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
71 | GCObject *ts; | 71 | GCObject *o; |
72 | lu_hash h = (lu_hash)l; /* seed */ | 72 | lu_hash h = (lu_hash)l; /* seed */ |
73 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ | 73 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
74 | size_t l1; | 74 | size_t l1; |
75 | for (l1=l; l1>=step; l1-=step) /* compute hash */ | 75 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
76 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)(str[l1-1])); | 76 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)(str[l1-1])); |
77 | for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; | 77 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; |
78 | ts != NULL; | 78 | o != NULL; |
79 | ts = ts->gch.next) { | 79 | o = o->gch.next) { |
80 | if ((&ts->ts)->tsv.len == l && (memcmp(str, getstr(&ts->ts), l) == 0)) | 80 | TString *ts = gcotots(o); |
81 | return &ts->ts; | 81 | if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) |
82 | return ts; | ||
82 | } | 83 | } |
83 | return newlstr(L, str, l, h); /* not found */ | 84 | return newlstr(L, str, l, h); /* not found */ |
84 | } | 85 | } |
@@ -93,7 +94,7 @@ Udata *luaS_newudata (lua_State *L, size_t s) { | |||
93 | u->uv.metatable = hvalue(defaultmeta(L)); | 94 | u->uv.metatable = hvalue(defaultmeta(L)); |
94 | /* chain it on udata list */ | 95 | /* chain it on udata list */ |
95 | u->uv.next = G(L)->rootudata; | 96 | u->uv.next = G(L)->rootudata; |
96 | G(L)->rootudata = cast(GCObject *, u); | 97 | G(L)->rootudata = valtogco(u); |
97 | return u; | 98 | return u; |
98 | } | 99 | } |
99 | 100 | ||