2
0
Эх сурвалжийг харах

Removed parameter in 'collectgarbage("step")'

A call to 'collectgarbage("step")' always performs one GC basic step.
Roberto Ierusalimschy 1 жил өмнө
parent
commit
b719ff9399
2 өөрчлөгдсөн 3 нэмэгдсэн , 57 устгасан
  1. 2 16
      lapi.c
  2. 1 41
      testes/gc.lua

+ 2 - 16
lapi.c

@@ -1191,25 +1191,11 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
       break;
     }
     case LUA_GCSTEP: {
-      int todo = va_arg(argp, int);  /* work to be done */
-      int didsomething = 0;
       lu_byte oldstp = g->gcstp;
       g->gcstp = 0;  /* allow GC to run (other bits must be zero here) */
-      if (todo == 0)
-        todo = 1 << g->gcstepsize;  /* standard step size */
-      while (todo >= g->GCdebt) {  /* enough to run a step? */
-        todo -= g->GCdebt;  /* decrement 'todo' */
-        luaC_step(L);  /* run one basic step */
-        didsomething = 1;
-        if (g->gckind == KGC_GEN)  /* minor collections? */
-          todo = 0;  /* doesn't make sense to repeat in this case */
-        else if (g->gcstate == GCSpause)
-          break;  /* don't run more than one cycle */
-      }
-      /* remove remaining 'todo' from total debt */
-      luaE_setdebt(g, g->GCdebt - todo);
+      luaC_step(L);  /* run one basic step */
       g->gcstp = oldstp;  /* restore previous state */
-      if (didsomething && g->gcstate == GCSpause)  /* end of cycle? */
+      if (g->gcstate == GCSpause)  /* end of cycle? */
         res = 1;  /* signal it */
       break;
     }

+ 1 - 41
testes/gc.lua

@@ -33,8 +33,7 @@ do
     for j = 1, #t do
       local m = t[j]
       collectgarbage("incremental", p, m)
-      collectgarbage("step", 0)
-      collectgarbage("step", 10000)
+      collectgarbage("step")
     end
   end
   -- restore original parameters
@@ -169,45 +168,6 @@ do
 end
 
 
---
--- test the "size" of basic GC steps (whatever they mean...)
---
-do
-print("steps")
-
-  print("steps (2)")
-
-  local function dosteps (siz)
-    collectgarbage()
-    local a = {}
-    for i=1,100 do a[i] = {{}}; local b = {} end
-    local x = gcinfo()
-    local i = 0
-    repeat   -- do steps until it completes a collection cycle
-      i = i+1
-    until collectgarbage("step", siz)
-    assert(gcinfo() < x)
-    return i    -- number of steps
-  end
-
-  collectgarbage"stop"
-
-  if not _port then
-    assert(dosteps(10) < dosteps(2))
-  end
-
-  -- collector should do a full collection with so many steps
-  assert(dosteps(20000) == 1)
-  assert(collectgarbage("step", 20000) == true)
-  assert(collectgarbage("step", 20000) == true)
-
-  assert(not collectgarbage("isrunning"))
-  collectgarbage"restart"
-  assert(collectgarbage("isrunning"))
-
-end
-
-
 if not _port then
   -- test the pace of the collector
   collectgarbage(); collectgarbage()