diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-10 13:33:20 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-10 13:33:20 -0300 |
| commit | 330e51bed3159aa83dcc9cc559c22e7d84d37604 (patch) | |
| tree | 8d11540f124fe432e12296c85091947161fb3886 /lgc.c | |
| parent | 44b71ca81696dbec561c0172d1b81533f1c2153e (diff) | |
| download | lua-330e51bed3159aa83dcc9cc559c22e7d84d37604.tar.gz lua-330e51bed3159aa83dcc9cc559c22e7d84d37604.tar.bz2 lua-330e51bed3159aa83dcc9cc559c22e7d84d37604.zip | |
string hash uses one single hash table
Diffstat (limited to 'lgc.c')
| -rw-r--r-- | lgc.c | 55 |
1 files changed, 30 insertions, 25 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.47 2000/04/14 18:12:35 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.48 2000/05/08 19:32:53 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 | */ |
| @@ -166,36 +166,41 @@ static void collecttable (lua_State *L) { | |||
| 166 | ** with limit=1, that means all unmarked elements; | 166 | ** with limit=1, that means all unmarked elements; |
| 167 | ** with limit=MAX_INT, that means all elements. | 167 | ** with limit=MAX_INT, that means all elements. |
| 168 | */ | 168 | */ |
| 169 | static void collectstring (lua_State *L, int limit) { | 169 | static void collectstringtab (lua_State *L, int limit, stringtable *tb) { |
| 170 | TObject o; /* to call userdata `gc' tag method */ | ||
| 171 | int i; | 170 | int i; |
| 171 | TObject o; /* to call userdata `gc' tag method */ | ||
| 172 | ttype(&o) = TAG_USERDATA; | 172 | ttype(&o) = TAG_USERDATA; |
| 173 | for (i=0; i<NUM_HASHS; i++) { /* for each hash table */ | 173 | for (i=0; i<tb->size; i++) { /* for each list */ |
| 174 | stringtable *tb = &L->string_root[i]; | 174 | TString **p = &tb->hash[i]; |
| 175 | int j; | 175 | TString *next; |
| 176 | for (j=0; j<tb->size; j++) { /* for each list */ | 176 | while ((next = *p) != NULL) { |
| 177 | TString **p = &tb->hash[j]; | 177 | if (next->marked >= limit) { |
| 178 | TString *next; | 178 | if (next->marked < FIXMARK) /* does not change FIXMARKs */ |
| 179 | while ((next = *p) != NULL) { | 179 | next->marked = 0; |
| 180 | if (next->marked >= limit) { | 180 | p = &next->nexthash; |
| 181 | if (next->marked < FIXMARK) /* does not change FIXMARKs */ | 181 | } |
| 182 | next->marked = 0; | 182 | else { /* collect */ |
| 183 | p = &next->nexthash; | 183 | if (tb == &L->strt) /* is string? */ |
| 184 | } | 184 | L->nblocks -= gcsizestring(L, next->u.s.len); |
| 185 | else { /* collect */ | 185 | else { |
| 186 | if (next->constindex == -1) { /* is userdata? */ | 186 | tsvalue(&o) = next; |
| 187 | tsvalue(&o) = next; | 187 | luaD_gcTM(L, &o); |
| 188 | luaD_gcTM(L, &o); | 188 | L->nblocks -= gcsizeudata; |
| 189 | } | ||
| 190 | *p = next->nexthash; | ||
| 191 | luaS_free(L, next); | ||
| 192 | tb->nuse--; | ||
| 193 | } | 189 | } |
| 190 | *p = next->nexthash; | ||
| 191 | tb->nuse--; | ||
| 192 | luaM_free(L, next); | ||
| 194 | } | 193 | } |
| 195 | } | 194 | } |
| 196 | if ((tb->nuse+1)*6 < tb->size) | ||
| 197 | luaS_resize(L, tb, tb->size/2); /* table is too big */ | ||
| 198 | } | 195 | } |
| 196 | if (tb->nuse < (tb->size/4) && tb->size > 10) | ||
| 197 | luaS_resize(L, tb, tb->size/2); /* table is too big */ | ||
| 198 | } | ||
| 199 | |||
| 200 | |||
| 201 | static void collectstring (lua_State *L, int limit) { | ||
| 202 | collectstringtab(L, limit, &L->strt); | ||
| 203 | collectstringtab(L, limit, &L->udt); | ||
| 199 | } | 204 | } |
| 200 | 205 | ||
| 201 | 206 | ||
