aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/lgc.c b/lgc.c
index 32dd6471..0a2cc596 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.47 2000/04/14 18:12:35 roberto Exp roberto $ 2** $Id: lgc.c,v 1.48 2000/05/08 19:32:53 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*/
@@ -166,36 +166,41 @@ static void collecttable (lua_State *L) {
166** with limit=1, that means all unmarked elements; 166** with limit=1, that means all unmarked elements;
167** with limit=MAX_INT, that means all elements. 167** with limit=MAX_INT, that means all elements.
168*/ 168*/
169static void collectstring (lua_State *L, int limit) { 169static void collectstringtab (lua_State *L, int limit, stringtable *tb) {
170 TObject o; /* to call userdata `gc' tag method */
171 int i; 170 int i;
171 TObject o; /* to call userdata `gc' tag method */
172 ttype(&o) = TAG_USERDATA; 172 ttype(&o) = TAG_USERDATA;
173 for (i=0; i<NUM_HASHS; i++) { /* for each hash table */ 173 for (i=0; i<tb->size; i++) { /* for each list */
174 stringtable *tb = &L->string_root[i]; 174 TString **p = &tb->hash[i];
175 int j; 175 TString *next;
176 for (j=0; j<tb->size; j++) { /* for each list */ 176 while ((next = *p) != NULL) {
177 TString **p = &tb->hash[j]; 177 if (next->marked >= limit) {
178 TString *next; 178 if (next->marked < FIXMARK) /* does not change FIXMARKs */
179 while ((next = *p) != NULL) { 179 next->marked = 0;
180 if (next->marked >= limit) { 180 p = &next->nexthash;
181 if (next->marked < FIXMARK) /* does not change FIXMARKs */ 181 }
182 next->marked = 0; 182 else { /* collect */
183 p = &next->nexthash; 183 if (tb == &L->strt) /* is string? */
184 } 184 L->nblocks -= gcsizestring(L, next->u.s.len);
185 else { /* collect */ 185 else {
186 if (next->constindex == -1) { /* is userdata? */ 186 tsvalue(&o) = next;
187 tsvalue(&o) = next; 187 luaD_gcTM(L, &o);
188 luaD_gcTM(L, &o); 188 L->nblocks -= gcsizeudata;
189 }
190 *p = next->nexthash;
191 luaS_free(L, next);
192 tb->nuse--;
193 } 189 }
190 *p = next->nexthash;
191 tb->nuse--;
192 luaM_free(L, next);
194 } 193 }
195 } 194 }
196 if ((tb->nuse+1)*6 < tb->size)
197 luaS_resize(L, tb, tb->size/2); /* table is too big */
198 } 195 }
196 if (tb->nuse < (tb->size/4) && tb->size > 10)
197 luaS_resize(L, tb, tb->size/2); /* table is too big */
198}
199
200
201static void collectstring (lua_State *L, int limit) {
202 collectstringtab(L, limit, &L->strt);
203 collectstringtab(L, limit, &L->udt);
199} 204}
200 205
201 206