diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-10-14 17:13:31 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-10-14 17:13:31 -0200 |
commit | 4e9f2d13d5b6fa71ca480394e0b7e75463d4aeec (patch) | |
tree | d11eee681ce7b01a273e489f47e070494b51de1a /lgc.c | |
parent | b6ebbb2fee13aa223fdd12921cd0411e02db9dd0 (diff) | |
download | lua-4e9f2d13d5b6fa71ca480394e0b7e75463d4aeec.tar.gz lua-4e9f2d13d5b6fa71ca480394e0b7e75463d4aeec.tar.bz2 lua-4e9f2d13d5b6fa71ca480394e0b7e75463d4aeec.zip |
new implementation of hash tables.
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.27 1999/10/04 17:51:04 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.28 1999/10/11 16:13:11 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 | */ |
@@ -51,10 +51,10 @@ static void hashmark (Hash *h) { | |||
51 | if (!h->marked) { | 51 | if (!h->marked) { |
52 | int i; | 52 | int i; |
53 | h->marked = 1; | 53 | h->marked = 1; |
54 | for (i=nhash(h)-1; i>=0; i--) { | 54 | for (i=h->size-1; i>=0; i--) { |
55 | Node *n = node(h,i); | 55 | Node *n = node(h,i); |
56 | if (ttype(ref(n)) != LUA_T_NIL) { | 56 | if (ttype(key(n)) != LUA_T_NIL) { |
57 | markobject(&n->ref); | 57 | markobject(&n->key); |
58 | markobject(&n->val); | 58 | markobject(&n->val); |
59 | } | 59 | } |
60 | } | 60 | } |
@@ -157,11 +157,11 @@ static void collecttable (void) { | |||
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
160 | static void clear_global_list (void) { | 160 | static void clear_global_list (int limit) { |
161 | TaggedString **p = &L->rootglobal; | 161 | TaggedString **p = &L->rootglobal; |
162 | TaggedString *next; | 162 | TaggedString *next; |
163 | while ((next = *p) != NULL) { | 163 | while ((next = *p) != NULL) { |
164 | if (next->marked) p = &next->nextglobal; | 164 | if (next->marked >= limit) p = &next->nextglobal; |
165 | else *p = next->nextglobal; | 165 | else *p = next->nextglobal; |
166 | } | 166 | } |
167 | } | 167 | } |
@@ -176,7 +176,7 @@ static void collectstring (int limit) { | |||
176 | TObject o; /* to call userdata 'gc' tag method */ | 176 | TObject o; /* to call userdata 'gc' tag method */ |
177 | int i; | 177 | int i; |
178 | ttype(&o) = LUA_T_USERDATA; | 178 | ttype(&o) = LUA_T_USERDATA; |
179 | clear_global_list(); | 179 | clear_global_list(limit); |
180 | for (i=0; i<NUM_HASHS; i++) { /* for each hash table */ | 180 | for (i=0; i<NUM_HASHS; i++) { /* for each hash table */ |
181 | stringtable *tb = &L->string_root[i]; | 181 | stringtable *tb = &L->string_root[i]; |
182 | int j; | 182 | int j; |
@@ -200,6 +200,8 @@ static void collectstring (int limit) { | |||
200 | } | 200 | } |
201 | } | 201 | } |
202 | } | 202 | } |
203 | if ((tb->nuse+1)*6 < tb->size) | ||
204 | luaS_grow(tb); /* table is too big; `grow' it to a smaller size */ | ||
203 | } | 205 | } |
204 | } | 206 | } |
205 | 207 | ||
@@ -237,7 +239,8 @@ void luaC_collect (int all) { | |||
237 | collectstring(all?MAX_INT:1); | 239 | collectstring(all?MAX_INT:1); |
238 | collectproto(); | 240 | collectproto(); |
239 | collectclosure(); | 241 | collectclosure(); |
240 | luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */ | 242 | if (!all) |
243 | luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */ | ||
241 | } | 244 | } |
242 | 245 | ||
243 | 246 | ||