aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-25 12:16:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-25 12:16:26 -0300
commit26d1e21c89a481c2368ba934da8e192a164d8f99 (patch)
treeea2eaaade79264b71d0e18fef75bca70fc1f4766 /lgc.c
parent24a2c08145ecc9b5c528a46ba83bdd7b95dbdc02 (diff)
downloadlua-26d1e21c89a481c2368ba934da8e192a164d8f99.tar.gz
lua-26d1e21c89a481c2368ba934da8e192a164d8f99.tar.bz2
lua-26d1e21c89a481c2368ba934da8e192a164d8f99.zip
new way to handle "growing" vectors
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/lgc.c b/lgc.c
index ba75ef26..dca1bb98 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.19 1998/07/12 16:10:38 roberto Exp roberto $ 2** $Id: lgc.c,v 1.20 1999/01/22 18:08:03 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*/
@@ -29,23 +29,19 @@ static int markobject (TObject *o);
29*/ 29*/
30 30
31 31
32int luaC_ref (TObject *o, int lock) 32int luaC_ref (TObject *o, int lock) {
33{
34 int ref; 33 int ref;
35 if (ttype(o) == LUA_T_NIL) 34 if (ttype(o) == LUA_T_NIL)
36 ref = -1; /* special ref for nil */ 35 ref = -1; /* special ref for nil */
37 else { 36 else {
38 for (ref=0; ref<L->refSize; ref++) 37 for (ref=0; ref<L->refSize; ref++)
39 if (L->refArray[ref].status == FREE) 38 if (L->refArray[ref].status == FREE)
40 goto found; 39 break;
41 /* no more empty spaces */ { 40 if (ref == L->refSize) { /* no more empty spaces? */
42 int oldSize = L->refSize; 41 L->refArray = luaM_growvector(L->refArray, L->refSize, 1, struct ref,
43 L->refSize = luaM_growvector(&L->refArray, L->refSize, struct ref, 42 refEM, MAX_INT);
44 refEM, MAX_INT); 43 L->refSize++;
45 for (ref=oldSize; ref<L->refSize; ref++) 44 }
46 L->refArray[ref].status = FREE;
47 ref = oldSize;
48 } found:
49 L->refArray[ref].o = *o; 45 L->refArray[ref].o = *o;
50 L->refArray[ref].status = lock ? LOCK : HOLD; 46 L->refArray[ref].status = lock ? LOCK : HOLD;
51 } 47 }