diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-23 14:26:37 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-23 14:26:37 -0200 |
| commit | 907368ead5978b689a97118b75e89a2095122530 (patch) | |
| tree | ed428793e87ab4a3c8de49be5586878af54c8d34 /lstring.c | |
| parent | 81489beea1a201b58dba964b6bbfd263f3683f25 (diff) | |
| download | lua-907368ead5978b689a97118b75e89a2095122530.tar.gz lua-907368ead5978b689a97118b75e89a2095122530.tar.bz2 lua-907368ead5978b689a97118b75e89a2095122530.zip | |
GC now considers an "estimate" of object size, instead of just the number
of objects.
Diffstat (limited to 'lstring.c')
| -rw-r--r-- | lstring.c | 13 |
1 files changed, 9 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ |
| 3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -16,6 +16,9 @@ | |||
| 16 | #define NUM_HASHS 61 | 16 | #define NUM_HASHS 61 |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | #define gcsizestring(l) (1+(l/64)) | ||
| 20 | |||
| 21 | |||
| 19 | GCnode luaS_root = {NULL, 0}; /* list of global variables */ | 22 | GCnode luaS_root = {NULL, 0}; /* list of global variables */ |
| 20 | 23 | ||
| 21 | 24 | ||
| @@ -89,16 +92,19 @@ static TaggedString *newone(char *buff, int tag, unsigned long h) | |||
| 89 | { | 92 | { |
| 90 | TaggedString *ts; | 93 | TaggedString *ts; |
| 91 | if (tag == LUA_T_STRING) { | 94 | if (tag == LUA_T_STRING) { |
| 92 | ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+strlen(buff)); | 95 | long l = strlen(buff); |
| 96 | ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l); | ||
| 93 | strcpy(ts->str, buff); | 97 | strcpy(ts->str, buff); |
| 94 | ts->u.globalval.ttype = LUA_T_NIL; /* initialize global value */ | 98 | ts->u.globalval.ttype = LUA_T_NIL; /* initialize global value */ |
| 95 | ts->constindex = 0; | 99 | ts->constindex = 0; |
| 100 | luaO_nblocks += gcsizestring(l); | ||
| 96 | } | 101 | } |
| 97 | else { | 102 | else { |
| 98 | ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)); | 103 | ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)); |
| 99 | ts->u.d.v = buff; | 104 | ts->u.d.v = buff; |
| 100 | ts->u.d.tag = tag == LUA_ANYTAG ? 0 : tag; | 105 | ts->u.d.tag = tag == LUA_ANYTAG ? 0 : tag; |
| 101 | ts->constindex = -1; /* tag -> this is a userdata */ | 106 | ts->constindex = -1; /* tag -> this is a userdata */ |
| 107 | luaO_nblocks++; | ||
| 102 | } | 108 | } |
| 103 | ts->head.marked = 0; | 109 | ts->head.marked = 0; |
| 104 | ts->head.next = (GCnode *)ts; /* signal it is in no list */ | 110 | ts->head.next = (GCnode *)ts; /* signal it is in no list */ |
| @@ -126,7 +132,6 @@ static TaggedString *insert (char *buff, int tag, stringtable *tb) | |||
| 126 | i = (i+1)%tb->size; | 132 | i = (i+1)%tb->size; |
| 127 | } | 133 | } |
| 128 | /* not found */ | 134 | /* not found */ |
| 129 | ++luaO_nentities; | ||
| 130 | if (j != -1) /* is there an EMPTY space? */ | 135 | if (j != -1) /* is there an EMPTY space? */ |
| 131 | i = j; | 136 | i = j; |
| 132 | else | 137 | else |
| @@ -158,6 +163,7 @@ void luaS_free (TaggedString *l) | |||
| 158 | { | 163 | { |
| 159 | while (l) { | 164 | while (l) { |
| 160 | TaggedString *next = (TaggedString *)l->head.next; | 165 | TaggedString *next = (TaggedString *)l->head.next; |
| 166 | luaO_nblocks -= (l->constindex == -1) ? 1 : gcsizestring(strlen(l->str)); | ||
| 161 | luaM_free(l); | 167 | luaM_free(l); |
| 162 | l = next; | 168 | l = next; |
| 163 | } | 169 | } |
| @@ -196,7 +202,6 @@ TaggedString *luaS_collector (void) | |||
| 196 | t->head.next = (GCnode *)frees; | 202 | t->head.next = (GCnode *)frees; |
| 197 | frees = t; | 203 | frees = t; |
| 198 | tb->hash[j] = &EMPTY; | 204 | tb->hash[j] = &EMPTY; |
| 199 | --luaO_nentities; | ||
| 200 | } | 205 | } |
| 201 | } | 206 | } |
| 202 | } | 207 | } |
