mirror of
https://github.com/lua/lua.git
synced 2025-01-14 05:43:00 +08:00
better way to traverse GCnode lists.
This commit is contained in:
parent
a580480b07
commit
eb617df2d8
21
lfunc.c
21
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;
|
||||
}
|
||||
|
||||
|
6
lfunc.h
6
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);
|
||||
|
36
lgc.c
36
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;
|
||||
|
11
lobject.c
11
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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
14
ltable.c
14
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user