diff options
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -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 | ||
32 | int luaC_ref (TObject *o, int lock) | 32 | int 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 | } |