diff options
Diffstat (limited to 'lgc.c')
| -rw-r--r-- | lgc.c | 36 |
1 files changed, 15 insertions, 21 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.2 1997/09/26 15:02:26 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 | */ |
| @@ -137,31 +137,25 @@ static void strcallIM (TaggedString *l) | |||
| 137 | 137 | ||
| 138 | 138 | ||
| 139 | 139 | ||
| 140 | static GCnode *listcollect (GCnode **root) | 140 | static GCnode *listcollect (GCnode *l) |
| 141 | { | 141 | { |
| 142 | GCnode *curr = *root, *prev = NULL, *frees = NULL; | 142 | GCnode *frees = NULL; |
| 143 | while (curr) { | 143 | while (l) { |
| 144 | GCnode *next = curr->next; | 144 | GCnode *next = l->next; |
| 145 | if (!curr->marked) { | 145 | l->marked = 0; |
| 146 | if (prev == NULL) | 146 | while (next && !next->marked) { |
| 147 | *root = next; | 147 | l->next = next->next; |
| 148 | else | 148 | next->next = frees; |
| 149 | prev->next = next; | 149 | frees = next; |
| 150 | curr->next = frees; | 150 | next = l->next; |
| 151 | frees = curr; | ||
| 152 | --luaO_nentities; | 151 | --luaO_nentities; |
| 153 | } | 152 | } |
| 154 | else { | 153 | l = next; |
| 155 | curr->marked = 0; | ||
| 156 | prev = curr; | ||
| 157 | } | ||
| 158 | curr = next; | ||
| 159 | } | 154 | } |
| 160 | return frees; | 155 | return frees; |
| 161 | } | 156 | } |
| 162 | 157 | ||
| 163 | 158 | ||
| 164 | |||
| 165 | static void strmark (TaggedString *s) | 159 | static void strmark (TaggedString *s) |
| 166 | { | 160 | { |
| 167 | if (!s->head.marked) | 161 | if (!s->head.marked) |
| @@ -280,9 +274,9 @@ long lua_collectgarbage (long limit) | |||
| 280 | markall(); | 274 | markall(); |
| 281 | invalidaterefs(); | 275 | invalidaterefs(); |
| 282 | freestr = luaS_collector(); | 276 | freestr = luaS_collector(); |
| 283 | freetable = (Hash *)listcollect((GCnode **)&luaH_root); | 277 | freetable = (Hash *)listcollect(&luaH_root); |
| 284 | freefunc = (TProtoFunc *)listcollect((GCnode **)&luaF_root); | 278 | freefunc = (TProtoFunc *)listcollect(&luaF_root); |
| 285 | freeclos = (Closure *)listcollect((GCnode **)&luaF_rootcl); | 279 | freeclos = (Closure *)listcollect(&luaF_rootcl); |
| 286 | recovered = recovered-luaO_nentities; | 280 | recovered = recovered-luaO_nentities; |
| 287 | /*printf("==total %ld coletados %ld\n", luaO_nentities+recovered, recovered);*/ | 281 | /*printf("==total %ld coletados %ld\n", luaO_nentities+recovered, recovered);*/ |
| 288 | luaC_threshold = (limit == 0) ? 2*luaO_nentities : luaO_nentities+limit; | 282 | luaC_threshold = (limit == 0) ? 2*luaO_nentities : luaO_nentities+limit; |
