diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-10-11 14:13:42 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-10-11 14:13:42 -0200 |
commit | c5fee7615e979e3a39af44614f82938519dedb68 (patch) | |
tree | 831ad8d88aba1d15e6337838d11e0234bd2e96d6 /lgc.c | |
parent | cca78b5c71f4def3d3d80c71f690f8380b3cb35e (diff) | |
download | lua-c5fee7615e979e3a39af44614f82938519dedb68.tar.gz lua-c5fee7615e979e3a39af44614f82938519dedb68.tar.bz2 lua-c5fee7615e979e3a39af44614f82938519dedb68.zip |
new implementation for string hashing, with chaining.
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.26 1999/09/27 18:00:25 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.27 1999/10/04 17:51:04 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -64,7 +64,7 @@ static void hashmark (Hash *h) { | |||
64 | 64 | ||
65 | static void globalmark (void) { | 65 | static void globalmark (void) { |
66 | TaggedString *g; | 66 | TaggedString *g; |
67 | for (g=L->rootglobal; g; g=g->next) { | 67 | for (g=L->rootglobal; g; g=g->nextglobal) { |
68 | LUA_ASSERT(g->constindex >= 0, "userdata in global list"); | 68 | LUA_ASSERT(g->constindex >= 0, "userdata in global list"); |
69 | if (g->u.s.globalval.ttype != LUA_T_NIL) { | 69 | if (g->u.s.globalval.ttype != LUA_T_NIL) { |
70 | markobject(&g->u.s.globalval); | 70 | markobject(&g->u.s.globalval); |
@@ -161,8 +161,8 @@ static void clear_global_list (void) { | |||
161 | TaggedString **p = &L->rootglobal; | 161 | TaggedString **p = &L->rootglobal; |
162 | TaggedString *next; | 162 | TaggedString *next; |
163 | while ((next = *p) != NULL) { | 163 | while ((next = *p) != NULL) { |
164 | if (next->marked) p = &next->next; | 164 | if (next->marked) p = &next->nextglobal; |
165 | else *p = next->next; | 165 | else *p = next->nextglobal; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
@@ -177,22 +177,28 @@ static void collectstring (int limit) { | |||
177 | int i; | 177 | int i; |
178 | ttype(&o) = LUA_T_USERDATA; | 178 | ttype(&o) = LUA_T_USERDATA; |
179 | clear_global_list(); | 179 | clear_global_list(); |
180 | for (i=0; i<NUM_HASHS; i++) { | 180 | for (i=0; i<NUM_HASHS; i++) { /* for each hash table */ |
181 | stringtable *tb = &L->string_root[i]; | 181 | stringtable *tb = &L->string_root[i]; |
182 | int j; | 182 | int j; |
183 | for (j=0; j<tb->size; j++) { | 183 | for (j=0; j<tb->size; j++) { /* for each list */ |
184 | TaggedString *t = tb->hash[j]; | 184 | TaggedString **p = &tb->hash[j]; |
185 | if (t == NULL) continue; | 185 | TaggedString *next; |
186 | if (t->marked < limit) { | 186 | while ((next = *p) != NULL) { |
187 | if (t->constindex == -1) { /* is userdata? */ | 187 | if (next->marked >= limit) { |
188 | tsvalue(&o) = t; | 188 | if (next->marked < FIXMARK) /* does not change FIXMARKs */ |
189 | luaD_gcIM(&o); | 189 | next->marked = 0; |
190 | p = &next->nexthash; | ||
191 | } | ||
192 | else { /* collect */ | ||
193 | if (next->constindex == -1) { /* is userdata? */ | ||
194 | tsvalue(&o) = next; | ||
195 | luaD_gcIM(&o); | ||
196 | } | ||
197 | *p = next->nexthash; | ||
198 | luaS_free(next); | ||
199 | tb->nuse--; | ||
190 | } | 200 | } |
191 | luaS_free(t); | ||
192 | tb->hash[j] = &luaS_EMPTY; | ||
193 | } | 201 | } |
194 | else if (t->marked == 1) | ||
195 | t->marked = 0; | ||
196 | } | 202 | } |
197 | } | 203 | } |
198 | } | 204 | } |