summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-09-26 13:46:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-09-26 13:46:20 -0300
commiteb617df2d87f8476e722ade7319998d7912a6edf (patch)
tree25d2635a076263518cdbb7da1693b674e0a4541e
parenta580480b07cdf7201306b246deeb2fe84f2c25a9 (diff)
downloadlua-github-eb617df2d87f8476e722ade7319998d7912a6edf.tar.gz
better way to traverse GCnode lists.
-rw-r--r--lfunc.c21
-rw-r--r--lfunc.h6
-rw-r--r--lgc.c36
-rw-r--r--lobject.c11
-rw-r--r--lobject.h3
-rw-r--r--ltable.c14
-rw-r--r--ltable.h4
7 files changed, 40 insertions, 55 deletions
diff --git a/lfunc.c b/lfunc.c
index c84ab973..3f13a89a 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
/*
-** $Id: $
+** $Id: lfunc.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
** Lua Funcion auxiliar
** See Copyright Notice in lua.h
*/
@@ -11,26 +11,15 @@
#include "lmem.h"
-TProtoFunc *luaF_root = NULL;
-Closure *luaF_rootcl = NULL;
+GCnode luaF_root = {NULL, 0};
+GCnode luaF_rootcl = {NULL, 0};
-static void luaI_insertfunction (TProtoFunc *f)
-{
- ++luaO_nentities;
- f->head.next = (GCnode *)luaF_root;
- luaF_root = f;
- f->head.marked = 0;
-}
-
Closure *luaF_newclosure (int nelems)
{
Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
- ++luaO_nentities;
- c->head.next = (GCnode *)luaF_rootcl;
- luaF_rootcl = c;
- c->head.marked = 0;
+ luaO_insertlist(&luaF_rootcl, (GCnode *)c);
return c;
}
@@ -45,7 +34,7 @@ TProtoFunc *luaF_newproto (void)
f->nconsts = 0;
f->nupvalues = 0;
f->locvars = NULL;
- luaI_insertfunction(f);
+ luaO_insertlist(&luaF_root, (GCnode *)f);
return f;
}
diff --git a/lfunc.h b/lfunc.h
index ed5a085b..4a7a6ac9 100644
--- a/lfunc.h
+++ b/lfunc.h
@@ -1,5 +1,5 @@
/*
-** $Id: $
+** $Id: lfunc.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
** Lua Function structures
** See Copyright Notice in lua.h
*/
@@ -11,8 +11,8 @@
#include "lobject.h"
-extern TProtoFunc *luaF_root;
-extern Closure *luaF_rootcl;
+extern GCnode luaF_root;
+extern GCnode luaF_rootcl;
TProtoFunc *luaF_newproto (void);
diff --git a/lgc.c b/lgc.c
index 87e37d19..6633d6a1 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
+** $Id: lgc.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -137,31 +137,25 @@ static void strcallIM (TaggedString *l)
-static GCnode *listcollect (GCnode **root)
+static GCnode *listcollect (GCnode *l)
{
- GCnode *curr = *root, *prev = NULL, *frees = NULL;
- while (curr) {
- GCnode *next = curr->next;
- if (!curr->marked) {
- if (prev == NULL)
- *root = next;
- else
- prev->next = next;
- curr->next = frees;
- frees = curr;
+ GCnode *frees = NULL;
+ while (l) {
+ GCnode *next = l->next;
+ l->marked = 0;
+ while (next && !next->marked) {
+ l->next = next->next;
+ next->next = frees;
+ frees = next;
+ next = l->next;
--luaO_nentities;
}
- else {
- curr->marked = 0;
- prev = curr;
- }
- curr = next;
+ l = next;
}
return frees;
}
-
static void strmark (TaggedString *s)
{
if (!s->head.marked)
@@ -280,9 +274,9 @@ long lua_collectgarbage (long limit)
markall();
invalidaterefs();
freestr = luaS_collector();
- freetable = (Hash *)listcollect((GCnode **)&luaH_root);
- freefunc = (TProtoFunc *)listcollect((GCnode **)&luaF_root);
- freeclos = (Closure *)listcollect((GCnode **)&luaF_rootcl);
+ freetable = (Hash *)listcollect(&luaH_root);
+ freefunc = (TProtoFunc *)listcollect(&luaF_root);
+ freeclos = (Closure *)listcollect(&luaF_rootcl);
recovered = recovered-luaO_nentities;
/*printf("==total %ld coletados %ld\n", luaO_nentities+recovered, recovered);*/
luaC_threshold = (limit == 0) ? 2*luaO_nentities : luaO_nentities+limit;
diff --git a/lobject.c b/lobject.c
index b9cabb0b..e06e89e5 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
/*
-** $Id: $
+** $Id: lobject.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@@ -66,3 +66,12 @@ int luaO_findstring (char *name, char *list[])
return -1; /* name not found */
}
+
+void luaO_insertlist (GCnode *root, GCnode *node)
+{
+ ++luaO_nentities;
+ node->next = root->next;
+ root->next = node;
+ node->marked = 0;
+}
+
diff --git a/lobject.h b/lobject.h
index 398155f2..fcfb7d3b 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
+** $Id: lobject.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -163,6 +163,7 @@ extern char *luaO_typenames[];
int luaO_equalObj (TObject *t1, TObject *t2);
int luaO_redimension (int oldsize);
int luaO_findstring (char *name, char *list[]);
+void luaO_insertlist (GCnode *root, GCnode *node);
#endif
diff --git a/ltable.c b/ltable.c
index 6279d936..4e0eb59f 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.c,v 1.1 1997/08/14 20:19:10 roberto Exp roberto $
+** $Id: ltable.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -23,7 +23,7 @@
#define TagDefault LUA_T_ARRAY;
-Hash *luaH_root = NULL;
+GCnode luaH_root = {NULL, 0};
@@ -103,14 +103,6 @@ void luaH_free (Hash *frees)
}
-static void inserttable (Hash *table)
-{
- ++luaO_nentities;
- table->head.next = (GCnode *)luaH_root;
- luaH_root = table;
- table->head.marked = 0;
-}
-
Hash *luaH_new (int nhash)
{
Hash *t = luaM_new(Hash);
@@ -119,7 +111,7 @@ Hash *luaH_new (int nhash)
nhash(t) = nhash;
nuse(t) = 0;
t->htag = TagDefault;
- inserttable(t);
+ luaO_insertlist(&luaH_root, (GCnode *)t);
return t;
}
diff --git a/ltable.h b/ltable.h
index 2633a63f..ff57591e 100644
--- a/ltable.h
+++ b/ltable.h
@@ -1,5 +1,5 @@
/*
-** $Id: $
+** $Id: ltable.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -10,7 +10,7 @@
#include "lobject.h"
-extern Hash *luaH_root;
+extern GCnode luaH_root;
#define node(t,i) (&(t)->node[i])