diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-09-29 09:42:13 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-09-29 09:42:13 -0300 |
| commit | dad808a73a98a23729614b8814728d76b4e5d577 (patch) | |
| tree | 945fabce1906c5f08fe6512476d7ca3d84017bca /lstring.c | |
| parent | ca7fd50a4ec2f1b41292f859ba0d5e52a2b22a5c (diff) | |
| download | lua-dad808a73a98a23729614b8814728d76b4e5d577.tar.gz lua-dad808a73a98a23729614b8814728d76b4e5d577.tar.bz2 lua-dad808a73a98a23729614b8814728d76b4e5d577.zip | |
new way to count `nblocks' for GC (try to count bytes).
Diffstat (limited to 'lstring.c')
| -rw-r--r-- | lstring.c | 9 |
1 files changed, 6 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.41 2000/08/04 19:38:35 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.42 2000/08/09 19:16:57 roberto Exp roberto $ |
| 3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -19,6 +19,7 @@ | |||
| 19 | void luaS_init (lua_State *L) { | 19 | void luaS_init (lua_State *L) { |
| 20 | L->strt.hash = luaM_newvector(L, 1, TString *); | 20 | L->strt.hash = luaM_newvector(L, 1, TString *); |
| 21 | L->udt.hash = luaM_newvector(L, 1, TString *); | 21 | L->udt.hash = luaM_newvector(L, 1, TString *); |
| 22 | L->nblocks += 2*sizeof(TString *); | ||
| 22 | L->strt.size = L->udt.size = 1; | 23 | L->strt.size = L->udt.size = 1; |
| 23 | L->strt.nuse = L->udt.nuse = 0; | 24 | L->strt.nuse = L->udt.nuse = 0; |
| 24 | L->strt.hash[0] = L->udt.hash[0] = NULL; | 25 | L->strt.hash[0] = L->udt.hash[0] = NULL; |
| @@ -27,6 +28,7 @@ void luaS_init (lua_State *L) { | |||
| 27 | 28 | ||
| 28 | void luaS_freeall (lua_State *L) { | 29 | void luaS_freeall (lua_State *L) { |
| 29 | LUA_ASSERT(L->strt.nuse==0, "non-empty string table"); | 30 | LUA_ASSERT(L->strt.nuse==0, "non-empty string table"); |
| 31 | L->nblocks -= (L->strt.size + L->udt.size)*sizeof(TString *); | ||
| 30 | luaM_free(L, L->strt.hash); | 32 | luaM_free(L, L->strt.hash); |
| 31 | LUA_ASSERT(L->udt.nuse==0, "non-empty udata table"); | 33 | LUA_ASSERT(L->udt.nuse==0, "non-empty udata table"); |
| 32 | luaM_free(L, L->udt.hash); | 34 | luaM_free(L, L->udt.hash); |
| @@ -61,6 +63,7 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) { | |||
| 61 | } | 63 | } |
| 62 | } | 64 | } |
| 63 | luaM_free(L, tb->hash); | 65 | luaM_free(L, tb->hash); |
| 66 | L->nblocks += (newsize - tb->size)*sizeof(TString *); | ||
| 64 | tb->size = newsize; | 67 | tb->size = newsize; |
| 65 | tb->hash = newhash; | 68 | tb->hash = newhash; |
| 66 | } | 69 | } |
| @@ -85,7 +88,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 85 | return ts; | 88 | return ts; |
| 86 | } | 89 | } |
| 87 | /* not found */ | 90 | /* not found */ |
| 88 | ts = (TString *)luaM_malloc(L, sizeof(TString)+(lint32)l*sizeof(char)); | 91 | ts = (TString *)luaM_malloc(L, sizestring(l)); |
| 89 | ts->marked = 0; | 92 | ts->marked = 0; |
| 90 | ts->nexthash = NULL; | 93 | ts->nexthash = NULL; |
| 91 | ts->u.s.len = l; | 94 | ts->u.s.len = l; |
| @@ -93,7 +96,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 93 | ts->u.s.constindex = 0; | 96 | ts->u.s.constindex = 0; |
| 94 | memcpy(ts->str, str, l); | 97 | memcpy(ts->str, str, l); |
| 95 | ts->str[l] = 0; /* ending 0 */ | 98 | ts->str[l] = 0; /* ending 0 */ |
| 96 | L->nblocks += gcsizestring(L, l); | 99 | L->nblocks += sizestring(l); |
| 97 | newentry(L, &L->strt, ts, h1); /* insert it on table */ | 100 | newentry(L, &L->strt, ts, h1); /* insert it on table */ |
| 98 | return ts; | 101 | return ts; |
| 99 | } | 102 | } |
