mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03: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
|
** Lua Funcion auxiliar
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -11,26 +11,15 @@
|
|||||||
#include "lmem.h"
|
#include "lmem.h"
|
||||||
|
|
||||||
|
|
||||||
TProtoFunc *luaF_root = NULL;
|
GCnode luaF_root = {NULL, 0};
|
||||||
Closure *luaF_rootcl = NULL;
|
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 *luaF_newclosure (int nelems)
|
||||||
{
|
{
|
||||||
Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
|
Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
|
||||||
++luaO_nentities;
|
luaO_insertlist(&luaF_rootcl, (GCnode *)c);
|
||||||
c->head.next = (GCnode *)luaF_rootcl;
|
|
||||||
luaF_rootcl = c;
|
|
||||||
c->head.marked = 0;
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +34,7 @@ TProtoFunc *luaF_newproto (void)
|
|||||||
f->nconsts = 0;
|
f->nconsts = 0;
|
||||||
f->nupvalues = 0;
|
f->nupvalues = 0;
|
||||||
f->locvars = NULL;
|
f->locvars = NULL;
|
||||||
luaI_insertfunction(f);
|
luaO_insertlist(&luaF_root, (GCnode *)f);
|
||||||
return 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
|
** Lua Function structures
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -11,8 +11,8 @@
|
|||||||
#include "lobject.h"
|
#include "lobject.h"
|
||||||
|
|
||||||
|
|
||||||
extern TProtoFunc *luaF_root;
|
extern GCnode luaF_root;
|
||||||
extern Closure *luaF_rootcl;
|
extern GCnode luaF_rootcl;
|
||||||
|
|
||||||
|
|
||||||
TProtoFunc *luaF_newproto (void);
|
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
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** 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;
|
GCnode *frees = NULL;
|
||||||
while (curr) {
|
while (l) {
|
||||||
GCnode *next = curr->next;
|
GCnode *next = l->next;
|
||||||
if (!curr->marked) {
|
l->marked = 0;
|
||||||
if (prev == NULL)
|
while (next && !next->marked) {
|
||||||
*root = next;
|
l->next = next->next;
|
||||||
else
|
next->next = frees;
|
||||||
prev->next = next;
|
frees = next;
|
||||||
curr->next = frees;
|
next = l->next;
|
||||||
frees = curr;
|
|
||||||
--luaO_nentities;
|
--luaO_nentities;
|
||||||
}
|
}
|
||||||
else {
|
l = next;
|
||||||
curr->marked = 0;
|
|
||||||
prev = curr;
|
|
||||||
}
|
|
||||||
curr = next;
|
|
||||||
}
|
}
|
||||||
return frees;
|
return frees;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void strmark (TaggedString *s)
|
static void strmark (TaggedString *s)
|
||||||
{
|
{
|
||||||
if (!s->head.marked)
|
if (!s->head.marked)
|
||||||
@ -280,9 +274,9 @@ long lua_collectgarbage (long limit)
|
|||||||
markall();
|
markall();
|
||||||
invalidaterefs();
|
invalidaterefs();
|
||||||
freestr = luaS_collector();
|
freestr = luaS_collector();
|
||||||
freetable = (Hash *)listcollect((GCnode **)&luaH_root);
|
freetable = (Hash *)listcollect(&luaH_root);
|
||||||
freefunc = (TProtoFunc *)listcollect((GCnode **)&luaF_root);
|
freefunc = (TProtoFunc *)listcollect(&luaF_root);
|
||||||
freeclos = (Closure *)listcollect((GCnode **)&luaF_rootcl);
|
freeclos = (Closure *)listcollect(&luaF_rootcl);
|
||||||
recovered = recovered-luaO_nentities;
|
recovered = recovered-luaO_nentities;
|
||||||
/*printf("==total %ld coletados %ld\n", luaO_nentities+recovered, recovered);*/
|
/*printf("==total %ld coletados %ld\n", luaO_nentities+recovered, recovered);*/
|
||||||
luaC_threshold = (limit == 0) ? 2*luaO_nentities : luaO_nentities+limit;
|
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
|
** Some generic functions over Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -66,3 +66,12 @@ int luaO_findstring (char *name, char *list[])
|
|||||||
return -1; /* name not found */
|
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
|
** Type definitions for Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -163,6 +163,7 @@ extern char *luaO_typenames[];
|
|||||||
int luaO_equalObj (TObject *t1, TObject *t2);
|
int luaO_equalObj (TObject *t1, TObject *t2);
|
||||||
int luaO_redimension (int oldsize);
|
int luaO_redimension (int oldsize);
|
||||||
int luaO_findstring (char *name, char *list[]);
|
int luaO_findstring (char *name, char *list[]);
|
||||||
|
void luaO_insertlist (GCnode *root, GCnode *node);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#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)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -23,7 +23,7 @@
|
|||||||
#define TagDefault LUA_T_ARRAY;
|
#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 *luaH_new (int nhash)
|
||||||
{
|
{
|
||||||
Hash *t = luaM_new(Hash);
|
Hash *t = luaM_new(Hash);
|
||||||
@ -119,7 +111,7 @@ Hash *luaH_new (int nhash)
|
|||||||
nhash(t) = nhash;
|
nhash(t) = nhash;
|
||||||
nuse(t) = 0;
|
nuse(t) = 0;
|
||||||
t->htag = TagDefault;
|
t->htag = TagDefault;
|
||||||
inserttable(t);
|
luaO_insertlist(&luaH_root, (GCnode *)t);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
ltable.h
4
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)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -10,7 +10,7 @@
|
|||||||
#include "lobject.h"
|
#include "lobject.h"
|
||||||
|
|
||||||
|
|
||||||
extern Hash *luaH_root;
|
extern GCnode luaH_root;
|
||||||
|
|
||||||
|
|
||||||
#define node(t,i) (&(t)->node[i])
|
#define node(t,i) (&(t)->node[i])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user