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 /hash.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 'hash.c')
-rw-r--r-- | hash.c | 70 |
1 files changed, 37 insertions, 33 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_hash="$Id: hash.c,v 2.41 1997/04/06 14:08:08 roberto Exp roberto $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.42 1997/05/08 20:43:30 roberto Exp roberto $"; |
7 | 7 | ||
8 | 8 | ||
9 | #include "luamem.h" | 9 | #include "luamem.h" |
@@ -167,46 +167,50 @@ void lua_hashmark (Hash *h) | |||
167 | } | 167 | } |
168 | 168 | ||
169 | 169 | ||
170 | void luaI_hashcallIM (void) | 170 | void luaI_hashcallIM (Hash *l) |
171 | { | 171 | { |
172 | Hash *curr_array; | ||
173 | TObject t; | 172 | TObject t; |
174 | ttype(&t) = LUA_T_ARRAY; | 173 | ttype(&t) = LUA_T_ARRAY; |
175 | for (curr_array = listhead; curr_array; curr_array = curr_array->next) | 174 | for (; l; l=l->next) { |
176 | if (markarray(curr_array) != 1) | 175 | avalue(&t) = l; |
177 | { | 176 | luaI_gcIM(&t); |
178 | avalue(&t) = curr_array; | 177 | } |
179 | luaI_gcIM(&t); | ||
180 | } | ||
181 | } | 178 | } |
182 | 179 | ||
183 | 180 | ||
184 | /* | 181 | void luaI_hashfree (Hash *frees) |
185 | ** Garbage collection to arrays | ||
186 | ** Delete all unmarked arrays. | ||
187 | */ | ||
188 | Long lua_hashcollector (void) | ||
189 | { | 182 | { |
190 | Hash *curr_array = listhead, *prev = NULL; | 183 | while (frees) { |
191 | Long counter = 0; | 184 | Hash *next = frees->next; |
192 | while (curr_array != NULL) | 185 | hashdelete(frees); |
193 | { | 186 | frees = next; |
194 | Hash *next = curr_array->next; | ||
195 | if (markarray(curr_array) != 1) | ||
196 | { | ||
197 | if (prev == NULL) listhead = next; | ||
198 | else prev->next = next; | ||
199 | hashdelete(curr_array); | ||
200 | ++counter; | ||
201 | } | 187 | } |
202 | else | 188 | } |
203 | { | 189 | |
204 | markarray(curr_array) = 0; | 190 | |
205 | prev = curr_array; | 191 | Hash *luaI_hashcollector (long *acum) |
192 | { | ||
193 | Hash *curr_array = listhead, *prev = NULL, *frees = NULL; | ||
194 | long counter = 0; | ||
195 | while (curr_array != NULL) { | ||
196 | Hash *next = curr_array->next; | ||
197 | if (markarray(curr_array) != 1) { | ||
198 | if (prev == NULL) | ||
199 | listhead = next; | ||
200 | else | ||
201 | prev->next = next; | ||
202 | curr_array->next = frees; | ||
203 | frees = curr_array; | ||
204 | ++counter; | ||
205 | } | ||
206 | else { | ||
207 | markarray(curr_array) = 0; | ||
208 | prev = curr_array; | ||
209 | } | ||
210 | curr_array = next; | ||
206 | } | 211 | } |
207 | curr_array = next; | 212 | *acum += counter; |
208 | } | 213 | return frees; |
209 | return counter; | ||
210 | } | 214 | } |
211 | 215 | ||
212 | 216 | ||