From 7061fe1d56f40e9d22a226423079da808fb41f66 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy <roberto@inf.puc-rio.br> Date: Wed, 11 Sep 2013 10:24:55 -0300 Subject: detail: 'sweepstep' checks end of phase after calling 'sweeplist', so that phases with small lists return 0 at the first call to 'sweepstep' --- lgc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lgc.c b/lgc.c index e9149167..c6f40a33 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.159 2013/09/11 12:26:14 roberto Exp roberto $ +** $Id: lgc.c,v 2.160 2013/09/11 12:47:48 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -740,7 +740,7 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { ** sweep a list until a live object (or end of list) */ static GCObject **sweeptolive (lua_State *L, GCObject **p, int *n) { - GCObject ** old = p; + GCObject **old = p; int i = 0; do { i++; @@ -1046,6 +1046,8 @@ static int entersweep (lua_State *L) { g->gcstate = GCSsweeplocal; lua_assert(g->sweepgc == NULL); g->sweepgc = sweeptolive(L, &g->localgc, &n); + if (g->sweepgc == NULL) /* no live objects in local list? */ + g->sweepgc = &g->localgc; /* 'sweepgc' cannot be NULL here */ return n; } @@ -1109,11 +1111,10 @@ static l_mem atomic (lua_State *L) { static lu_mem sweepstep (lua_State *L, global_State *g, int nextstate, GCObject **nextlist) { - if (g->sweepgc) { /* is there still something to sweep? */ - g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); + g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); + if (g->sweepgc) /* is there still something to sweep? */ return (GCSWEEPMAX * GCSWEEPCOST); - } - else { /* next phase */ + else { /* enter next state */ g->gcstate = nextstate; g->sweepgc = nextlist; return 0; -- cgit v1.2.3-55-g6feb