aboutsummaryrefslogtreecommitdiff
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-eb617df2d87f8476e722ade7319998d7912a6edf.tar.gz
lua-eb617df2d87f8476e722ade7319998d7912a6edf.tar.bz2
lua-eb617df2d87f8476e722ade7319998d7912a6edf.zip
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 @@
1/* 1/*
2** $Id: $ 2** $Id: lfunc.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
3** Lua Funcion auxiliar 3** Lua Funcion auxiliar
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,26 +11,15 @@
11#include "lmem.h" 11#include "lmem.h"
12 12
13 13
14TProtoFunc *luaF_root = NULL; 14GCnode luaF_root = {NULL, 0};
15Closure *luaF_rootcl = NULL; 15GCnode luaF_rootcl = {NULL, 0};
16 16
17 17
18static void luaI_insertfunction (TProtoFunc *f)
19{
20 ++luaO_nentities;
21 f->head.next = (GCnode *)luaF_root;
22 luaF_root = f;
23 f->head.marked = 0;
24}
25
26 18
27Closure *luaF_newclosure (int nelems) 19Closure *luaF_newclosure (int nelems)
28{ 20{
29 Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject)); 21 Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
30 ++luaO_nentities; 22 luaO_insertlist(&luaF_rootcl, (GCnode *)c);
31 c->head.next = (GCnode *)luaF_rootcl;
32 luaF_rootcl = c;
33 c->head.marked = 0;
34 return c; 23 return c;
35} 24}
36 25
@@ -45,7 +34,7 @@ TProtoFunc *luaF_newproto (void)
45 f->nconsts = 0; 34 f->nconsts = 0;
46 f->nupvalues = 0; 35 f->nupvalues = 0;
47 f->locvars = NULL; 36 f->locvars = NULL;
48 luaI_insertfunction(f); 37 luaO_insertlist(&luaF_root, (GCnode *)f);
49 return f; 38 return f;
50} 39}
51 40
diff --git a/lfunc.h b/lfunc.h
index ed5a085b..4a7a6ac9 100644
--- a/lfunc.h
+++ b/lfunc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: $ 2** $Id: lfunc.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
3** Lua Function structures 3** Lua Function structures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,8 +11,8 @@
11#include "lobject.h" 11#include "lobject.h"
12 12
13 13
14extern TProtoFunc *luaF_root; 14extern GCnode luaF_root;
15extern Closure *luaF_rootcl; 15extern GCnode luaF_rootcl;
16 16
17 17
18TProtoFunc *luaF_newproto (void); 18TProtoFunc *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 @@
1/* 1/*
2** $Id: lgc.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ 2** $Id: lgc.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -137,31 +137,25 @@ static void strcallIM (TaggedString *l)
137 137
138 138
139 139
140static GCnode *listcollect (GCnode **root) 140static GCnode *listcollect (GCnode *l)
141{ 141{
142 GCnode *curr = *root, *prev = NULL, *frees = NULL; 142 GCnode *frees = NULL;
143 while (curr) { 143 while (l) {
144 GCnode *next = curr->next; 144 GCnode *next = l->next;
145 if (!curr->marked) { 145 l->marked = 0;
146 if (prev == NULL) 146 while (next && !next->marked) {
147 *root = next; 147 l->next = next->next;
148 else 148 next->next = frees;
149 prev->next = next; 149 frees = next;
150 curr->next = frees; 150 next = l->next;
151 frees = curr;
152 --luaO_nentities; 151 --luaO_nentities;
153 } 152 }
154 else { 153 l = next;
155 curr->marked = 0;
156 prev = curr;
157 }
158 curr = next;
159 } 154 }
160 return frees; 155 return frees;
161} 156}
162 157
163 158
164
165static void strmark (TaggedString *s) 159static void strmark (TaggedString *s)
166{ 160{
167 if (!s->head.marked) 161 if (!s->head.marked)
@@ -280,9 +274,9 @@ long lua_collectgarbage (long limit)
280 markall(); 274 markall();
281 invalidaterefs(); 275 invalidaterefs();
282 freestr = luaS_collector(); 276 freestr = luaS_collector();
283 freetable = (Hash *)listcollect((GCnode **)&luaH_root); 277 freetable = (Hash *)listcollect(&luaH_root);
284 freefunc = (TProtoFunc *)listcollect((GCnode **)&luaF_root); 278 freefunc = (TProtoFunc *)listcollect(&luaF_root);
285 freeclos = (Closure *)listcollect((GCnode **)&luaF_rootcl); 279 freeclos = (Closure *)listcollect(&luaF_rootcl);
286 recovered = recovered-luaO_nentities; 280 recovered = recovered-luaO_nentities;
287/*printf("==total %ld coletados %ld\n", luaO_nentities+recovered, recovered);*/ 281/*printf("==total %ld coletados %ld\n", luaO_nentities+recovered, recovered);*/
288 luaC_threshold = (limit == 0) ? 2*luaO_nentities : luaO_nentities+limit; 282 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 @@
1/* 1/*
2** $Id: $ 2** $Id: lobject.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -66,3 +66,12 @@ int luaO_findstring (char *name, char *list[])
66 return -1; /* name not found */ 66 return -1; /* name not found */
67} 67}
68 68
69
70void luaO_insertlist (GCnode *root, GCnode *node)
71{
72 ++luaO_nentities;
73 node->next = root->next;
74 root->next = node;
75 node->marked = 0;
76}
77
diff --git a/lobject.h b/lobject.h
index 398155f2..fcfb7d3b 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ 2** $Id: lobject.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -163,6 +163,7 @@ extern char *luaO_typenames[];
163int luaO_equalObj (TObject *t1, TObject *t2); 163int luaO_equalObj (TObject *t1, TObject *t2);
164int luaO_redimension (int oldsize); 164int luaO_redimension (int oldsize);
165int luaO_findstring (char *name, char *list[]); 165int luaO_findstring (char *name, char *list[]);
166void luaO_insertlist (GCnode *root, GCnode *node);
166 167
167 168
168#endif 169#endif
diff --git a/ltable.c b/ltable.c
index 6279d936..4e0eb59f 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.1 1997/08/14 20:19:10 roberto Exp roberto $ 2** $Id: ltable.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -23,7 +23,7 @@
23#define TagDefault LUA_T_ARRAY; 23#define TagDefault LUA_T_ARRAY;
24 24
25 25
26Hash *luaH_root = NULL; 26GCnode luaH_root = {NULL, 0};
27 27
28 28
29 29
@@ -103,14 +103,6 @@ void luaH_free (Hash *frees)
103} 103}
104 104
105 105
106static void inserttable (Hash *table)
107{
108 ++luaO_nentities;
109 table->head.next = (GCnode *)luaH_root;
110 luaH_root = table;
111 table->head.marked = 0;
112}
113
114Hash *luaH_new (int nhash) 106Hash *luaH_new (int nhash)
115{ 107{
116 Hash *t = luaM_new(Hash); 108 Hash *t = luaM_new(Hash);
@@ -119,7 +111,7 @@ Hash *luaH_new (int nhash)
119 nhash(t) = nhash; 111 nhash(t) = nhash;
120 nuse(t) = 0; 112 nuse(t) = 0;
121 t->htag = TagDefault; 113 t->htag = TagDefault;
122 inserttable(t); 114 luaO_insertlist(&luaH_root, (GCnode *)t);
123 return t; 115 return t;
124} 116}
125 117
diff --git a/ltable.h b/ltable.h
index 2633a63f..ff57591e 100644
--- a/ltable.h
+++ b/ltable.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: $ 2** $Id: ltable.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -10,7 +10,7 @@
10#include "lobject.h" 10#include "lobject.h"
11 11
12 12
13extern Hash *luaH_root; 13extern GCnode luaH_root;
14 14
15 15
16#define node(t,i) (&(t)->node[i]) 16#define node(t,i) (&(t)->node[i])