diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-05-14 15:38:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-05-14 15:38:29 -0300 |
commit | bd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45 (patch) | |
tree | f11ad6c42c0bb42eaa1b45548684fbc60c27996b /tree.c | |
parent | 9747f3c87a205d9aa914a650686d6dc4accde1d9 (diff) | |
download | lua-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.c | 41 |
1 files changed, 23 insertions, 18 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_tree="$Id: tree.c,v 1.24 1997/03/31 14:17:09 roberto Exp roberto $"; | 6 | char *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 | ||
30 | static stringtable string_root[NUM_HASHS]; | 30 | static stringtable string_root[NUM_HASHS]; |
31 | 31 | ||
32 | static TaggedString EMPTY = {LUA_T_STRING, 0, NOT_USED, NOT_USED, 0, 2, {0}}; | 32 | static TaggedString EMPTY = {LUA_T_STRING, NULL, 0, NOT_USED, NOT_USED, |
33 | 0, 2, {0}}; | ||
33 | 34 | ||
34 | 35 | ||
35 | static unsigned long hash (char *buff, long size) | 36 | static unsigned long hash (char *buff, long size) |
@@ -134,32 +135,34 @@ TaggedString *lua_createstring (char *str) | |||
134 | } | 135 | } |
135 | 136 | ||
136 | 137 | ||
137 | void luaI_strcallIM (void) | 138 | void 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); | 149 | void 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 | */ |
160 | Long lua_strcollector (void) | 162 | TaggedString *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 | ||