From 907368ead5978b689a97118b75e89a2095122530 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 23 Oct 1997 14:26:37 -0200 Subject: GC now considers an "estimate" of object size, instead of just the number of objects. --- ltable.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'ltable.c') diff --git a/ltable.c b/ltable.c index a894c3fa..71d49dcb 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 1.2 1997/09/26 16:46:20 roberto Exp roberto $ +** $Id: ltable.c,v 1.3 1997/10/18 16:29:15 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -13,6 +13,8 @@ #include "lua.h" +#define gcsize(n) (1+(n/16)) + #define nuse(t) ((t)->nuse) #define nodevector(t) ((t)->node) @@ -75,11 +77,11 @@ static int present (Hash *t, TObject *key) */ static Node *hashnodecreate (int nhash) { - int i; - Node *v = luaM_newvector (nhash, Node); - for (i=0; ihead.next; + luaO_nblocks -= gcsize(frees->nhash); hashdelete(frees); frees = next; } @@ -111,6 +114,7 @@ Hash *luaH_new (int nhash) nuse(t) = 0; t->htag = TagDefault; luaO_insertlist(&luaH_root, (GCnode *)t); + luaO_nblocks += gcsize(nhash); return t; } @@ -144,6 +148,7 @@ static void rehash (Hash *t) if (ttype(ref(n)) != LUA_T_NIL && ttype(val(n)) != LUA_T_NIL) *node(t, present(t, ref(n))) = *n; /* copy old node to luaM_new hash */ } + luaO_nblocks += gcsize(t->nhash)-gcsize(nold); luaM_free(vold); } -- cgit v1.2.3-55-g6feb