From dad808a73a98a23729614b8814728d76b4e5d577 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 29 Sep 2000 09:42:13 -0300 Subject: new way to count `nblocks' for GC (try to count bytes). --- lstring.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lstring.c') diff --git a/lstring.c b/lstring.c index 1b0551c3..02dd54c1 100644 --- a/lstring.c +++ b/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 1.41 2000/08/04 19:38:35 roberto Exp roberto $ +** $Id: lstring.c,v 1.42 2000/08/09 19:16:57 roberto Exp roberto $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -19,6 +19,7 @@ void luaS_init (lua_State *L) { L->strt.hash = luaM_newvector(L, 1, TString *); L->udt.hash = luaM_newvector(L, 1, TString *); + L->nblocks += 2*sizeof(TString *); L->strt.size = L->udt.size = 1; L->strt.nuse = L->udt.nuse = 0; L->strt.hash[0] = L->udt.hash[0] = NULL; @@ -27,6 +28,7 @@ void luaS_init (lua_State *L) { void luaS_freeall (lua_State *L) { LUA_ASSERT(L->strt.nuse==0, "non-empty string table"); + L->nblocks -= (L->strt.size + L->udt.size)*sizeof(TString *); luaM_free(L, L->strt.hash); LUA_ASSERT(L->udt.nuse==0, "non-empty udata table"); luaM_free(L, L->udt.hash); @@ -61,6 +63,7 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) { } } luaM_free(L, tb->hash); + L->nblocks += (newsize - tb->size)*sizeof(TString *); tb->size = newsize; tb->hash = newhash; } @@ -85,7 +88,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { return ts; } /* not found */ - ts = (TString *)luaM_malloc(L, sizeof(TString)+(lint32)l*sizeof(char)); + ts = (TString *)luaM_malloc(L, sizestring(l)); ts->marked = 0; ts->nexthash = NULL; ts->u.s.len = l; @@ -93,7 +96,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { ts->u.s.constindex = 0; memcpy(ts->str, str, l); ts->str[l] = 0; /* ending 0 */ - L->nblocks += gcsizestring(L, l); + L->nblocks += sizestring(l); newentry(L, &L->strt, ts, h1); /* insert it on table */ return ts; } -- cgit v1.2.3-55-g6feb