lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 7061fe1d56f40e9d22a226423079da808fb41f66
parent d8aa8dd97e14dfd724e997261d305f2045d1ca63
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Wed, 11 Sep 2013 10:24:30 -0300

detail: 'sweepstep' checks end of phase after calling 'sweeplist', so
that phases with small lists return 0 at the first call to 'sweepstep'

Diffstat:
Mlgc.c | 13+++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git 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;