aboutsummaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-05-14 15:38:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-05-14 15:38:29 -0300
commitbd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45 (patch)
treef11ad6c42c0bb42eaa1b45548684fbc60c27996b /tree.c
parent9747f3c87a205d9aa914a650686d6dc4accde1d9 (diff)
downloadlua-bd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45.tar.gz
lua-bd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45.tar.bz2
lua-bd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45.zip
new implementation of gc: "Pre-collect" garbage in temporary lists and
then call fallbacks.
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/tree.c b/tree.c
index 0141a99c..ea2b2dec 100644
--- a/tree.c
+++ b/tree.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_tree="$Id: tree.c,v 1.24 1997/03/31 14:17:09 roberto Exp roberto $"; 6char *rcs_tree="$Id: tree.c,v 1.25 1997/05/05 20:21:23 roberto Exp roberto $";
7 7
8 8
9#include <string.h> 9#include <string.h>
@@ -29,7 +29,8 @@ static int initialized = 0;
29 29
30static stringtable string_root[NUM_HASHS]; 30static stringtable string_root[NUM_HASHS];
31 31
32static TaggedString EMPTY = {LUA_T_STRING, 0, NOT_USED, NOT_USED, 0, 2, {0}}; 32static TaggedString EMPTY = {LUA_T_STRING, NULL, 0, NOT_USED, NOT_USED,
33 0, 2, {0}};
33 34
34 35
35static unsigned long hash (char *buff, long size) 36static unsigned long hash (char *buff, long size)
@@ -134,32 +135,34 @@ TaggedString *lua_createstring (char *str)
134} 135}
135 136
136 137
137void luaI_strcallIM (void) 138void luaI_strcallIM (TaggedString *l)
138{ 139{
139 int i;
140 TObject o; 140 TObject o;
141 ttype(&o) = LUA_T_USERDATA; 141 ttype(&o) = LUA_T_USERDATA;
142 for (i=0; i<NUM_HASHS; i++) { 142 for (; l; l=l->next) {
143 stringtable *tb = &string_root[i]; 143 tsvalue(&o) = l;
144 int j; 144 luaI_gcIM(&o);
145 for (j=0; j<tb->size; j++) { 145 }
146 TaggedString *t = tb->hash[j]; 146}
147 if (t != NULL && t->tag != LUA_T_STRING && t->marked == 0) { 147
148 tsvalue(&o) = t; 148
149 luaI_gcIM(&o); 149void luaI_strfree (TaggedString *l)
150 } 150{
151 } 151 while (l) {
152 TaggedString *next = l->next;
153 luaI_free(l);
154 l = next;
152 } 155 }
153} 156}
154 157
155 158
156/* 159/*
157** Garbage collection function. 160** Garbage collection function.
158** This function traverse the string list freeing unindexed strings
159*/ 161*/
160Long lua_strcollector (void) 162TaggedString *luaI_strcollector (long *acum)
161{ 163{
162 Long counter = 0; 164 Long counter = 0;
165 TaggedString *frees = NULL;
163 int i; 166 int i;
164 for (i=0; i<NUM_HASHS; i++) 167 for (i=0; i<NUM_HASHS; i++)
165 { 168 {
@@ -174,13 +177,15 @@ Long lua_strcollector (void)
174 t->marked = 0; 177 t->marked = 0;
175 else 178 else
176 { 179 {
177 luaI_free(t); 180 t->next = frees;
181 frees = t;
178 tb->hash[j] = &EMPTY; 182 tb->hash[j] = &EMPTY;
179 counter++; 183 counter++;
180 } 184 }
181 } 185 }
182 } 186 }
183 } 187 }
184 return counter; 188 *acum += counter;
189 return frees;
185} 190}
186 191