diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-26 13:46:20 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-26 13:46:20 -0300 |
| commit | eb617df2d87f8476e722ade7319998d7912a6edf (patch) | |
| tree | 25d2635a076263518cdbb7da1693b674e0a4541e | |
| parent | a580480b07cdf7201306b246deeb2fe84f2c25a9 (diff) | |
| download | lua-eb617df2d87f8476e722ade7319998d7912a6edf.tar.gz lua-eb617df2d87f8476e722ade7319998d7912a6edf.tar.bz2 lua-eb617df2d87f8476e722ade7319998d7912a6edf.zip | |
better way to traverse GCnode lists.
Diffstat (limited to '')
| -rw-r--r-- | lfunc.c | 21 | ||||
| -rw-r--r-- | lfunc.h | 6 | ||||
| -rw-r--r-- | lgc.c | 36 | ||||
| -rw-r--r-- | lobject.c | 11 | ||||
| -rw-r--r-- | lobject.h | 3 | ||||
| -rw-r--r-- | ltable.c | 14 | ||||
| -rw-r--r-- | ltable.h | 4 |
7 files changed, 40 insertions, 55 deletions
| @@ -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 | ||
| 14 | TProtoFunc *luaF_root = NULL; | 14 | GCnode luaF_root = {NULL, 0}; |
| 15 | Closure *luaF_rootcl = NULL; | 15 | GCnode luaF_rootcl = {NULL, 0}; |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | static 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 | ||
| 27 | Closure *luaF_newclosure (int nelems) | 19 | Closure *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 | ||
| @@ -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 | ||
| 14 | extern TProtoFunc *luaF_root; | 14 | extern GCnode luaF_root; |
| 15 | extern Closure *luaF_rootcl; | 15 | extern GCnode luaF_rootcl; |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | TProtoFunc *luaF_newproto (void); | 18 | TProtoFunc *luaF_newproto (void); |
| @@ -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 | ||
| 140 | static GCnode *listcollect (GCnode **root) | 140 | static 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 | |||
| 165 | static void strmark (TaggedString *s) | 159 | static 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; |
| @@ -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 | |||
| 70 | void 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 | |||
| @@ -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[]; | |||
| 163 | int luaO_equalObj (TObject *t1, TObject *t2); | 163 | int luaO_equalObj (TObject *t1, TObject *t2); |
| 164 | int luaO_redimension (int oldsize); | 164 | int luaO_redimension (int oldsize); |
| 165 | int luaO_findstring (char *name, char *list[]); | 165 | int luaO_findstring (char *name, char *list[]); |
| 166 | void luaO_insertlist (GCnode *root, GCnode *node); | ||
| 166 | 167 | ||
| 167 | 168 | ||
| 168 | #endif | 169 | #endif |
| @@ -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 | ||
| 26 | Hash *luaH_root = NULL; | 26 | GCnode 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 | ||
| 106 | static 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 | |||
| 114 | Hash *luaH_new (int nhash) | 106 | Hash *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 | ||
| @@ -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 | ||
| 13 | extern Hash *luaH_root; | 13 | extern GCnode luaH_root; |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | #define node(t,i) (&(t)->node[i]) | 16 | #define node(t,i) (&(t)->node[i]) |
