summaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/ltable.c b/ltable.c
index a894c3fa..71d49dcb 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.2 1997/09/26 16:46:20 roberto Exp roberto $ 2** $Id: ltable.c,v 1.3 1997/10/18 16:29:15 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*/
@@ -13,6 +13,8 @@
13#include "lua.h" 13#include "lua.h"
14 14
15 15
16#define gcsize(n) (1+(n/16))
17
16#define nuse(t) ((t)->nuse) 18#define nuse(t) ((t)->nuse)
17#define nodevector(t) ((t)->node) 19#define nodevector(t) ((t)->node)
18 20
@@ -75,11 +77,11 @@ static int present (Hash *t, TObject *key)
75*/ 77*/
76static Node *hashnodecreate (int nhash) 78static Node *hashnodecreate (int nhash)
77{ 79{
78 int i; 80 Node *v = luaM_newvector(nhash, Node);
79 Node *v = luaM_newvector (nhash, Node); 81 int i;
80 for (i=0; i<nhash; i++) 82 for (i=0; i<nhash; i++)
81 ttype(ref(&v[i])) = LUA_T_NIL; 83 ttype(ref(&v[i])) = LUA_T_NIL;
82 return v; 84 return v;
83} 85}
84 86
85/* 87/*
@@ -96,6 +98,7 @@ void luaH_free (Hash *frees)
96{ 98{
97 while (frees) { 99 while (frees) {
98 Hash *next = (Hash *)frees->head.next; 100 Hash *next = (Hash *)frees->head.next;
101 luaO_nblocks -= gcsize(frees->nhash);
99 hashdelete(frees); 102 hashdelete(frees);
100 frees = next; 103 frees = next;
101 } 104 }
@@ -111,6 +114,7 @@ Hash *luaH_new (int nhash)
111 nuse(t) = 0; 114 nuse(t) = 0;
112 t->htag = TagDefault; 115 t->htag = TagDefault;
113 luaO_insertlist(&luaH_root, (GCnode *)t); 116 luaO_insertlist(&luaH_root, (GCnode *)t);
117 luaO_nblocks += gcsize(nhash);
114 return t; 118 return t;
115} 119}
116 120
@@ -144,6 +148,7 @@ static void rehash (Hash *t)
144 if (ttype(ref(n)) != LUA_T_NIL && ttype(val(n)) != LUA_T_NIL) 148 if (ttype(ref(n)) != LUA_T_NIL && ttype(val(n)) != LUA_T_NIL)
145 *node(t, present(t, ref(n))) = *n; /* copy old node to luaM_new hash */ 149 *node(t, present(t, ref(n))) = *n; /* copy old node to luaM_new hash */
146 } 150 }
151 luaO_nblocks += gcsize(t->nhash)-gcsize(nold);
147 luaM_free(vold); 152 luaM_free(vold);
148} 153}
149 154