summaryrefslogtreecommitdiff
path: root/lstring.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-10-23 14:26:37 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-10-23 14:26:37 -0200
commit907368ead5978b689a97118b75e89a2095122530 (patch)
treeed428793e87ab4a3c8de49be5586878af54c8d34 /lstring.c
parent81489beea1a201b58dba964b6bbfd263f3683f25 (diff)
downloadlua-github-907368ead5978b689a97118b75e89a2095122530.tar.gz
GC now considers an "estimate" of object size, instead of just the number
of objects.
Diffstat (limited to 'lstring.c')
-rw-r--r--lstring.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/lstring.c b/lstring.c
index 1b82cf20..cc67c66d 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstring.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
+** $Id: lstring.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -16,6 +16,9 @@
#define NUM_HASHS 61
+#define gcsizestring(l) (1+(l/64))
+
+
GCnode luaS_root = {NULL, 0}; /* list of global variables */
@@ -89,16 +92,19 @@ static TaggedString *newone(char *buff, int tag, unsigned long h)
{
TaggedString *ts;
if (tag == LUA_T_STRING) {
- ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+strlen(buff));
+ long l = strlen(buff);
+ ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l);
strcpy(ts->str, buff);
ts->u.globalval.ttype = LUA_T_NIL; /* initialize global value */
ts->constindex = 0;
+ luaO_nblocks += gcsizestring(l);
}
else {
ts = (TaggedString *)luaM_malloc(sizeof(TaggedString));
ts->u.d.v = buff;
ts->u.d.tag = tag == LUA_ANYTAG ? 0 : tag;
ts->constindex = -1; /* tag -> this is a userdata */
+ luaO_nblocks++;
}
ts->head.marked = 0;
ts->head.next = (GCnode *)ts; /* signal it is in no list */
@@ -126,7 +132,6 @@ static TaggedString *insert (char *buff, int tag, stringtable *tb)
i = (i+1)%tb->size;
}
/* not found */
- ++luaO_nentities;
if (j != -1) /* is there an EMPTY space? */
i = j;
else
@@ -158,6 +163,7 @@ void luaS_free (TaggedString *l)
{
while (l) {
TaggedString *next = (TaggedString *)l->head.next;
+ luaO_nblocks -= (l->constindex == -1) ? 1 : gcsizestring(strlen(l->str));
luaM_free(l);
l = next;
}
@@ -196,7 +202,6 @@ TaggedString *luaS_collector (void)
t->head.next = (GCnode *)frees;
frees = t;
tb->hash[j] = &EMPTY;
- --luaO_nentities;
}
}
}