소스 검색

check for shrinking string table done only at the end of a GC cycle

Roberto Ierusalimschy 12 년 전
부모
커밋
6ca7b63bce
2개의 변경된 파일11개의 추가작업 그리고 8개의 파일을 삭제
  1. 10 5
      lgc.c
  2. 1 3
      lstring.c

+ 10 - 5
lgc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.c,v 2.162 2013/09/11 14:09:55 roberto Exp roberto $
+** $Id: lgc.c,v 2.163 2013/09/11 14:47:08 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -759,10 +759,15 @@ static GCObject **sweeptolive (lua_State *L, GCObject **p, int *n) {
 ** =======================================================
 */
 
-static void checkBuffer (lua_State *L) {
-  global_State *g = G(L);
-  if (g->gckind != KGC_EMERGENCY)
+/*
+** If possible, free concatenation buffer and shrink string table
+*/
+static void checkSizes (lua_State *L, global_State *g) {
+  if (g->gckind != KGC_EMERGENCY) {
     luaZ_freebuffer(L, &g->buff);  /* free concatenation buffer */
+    if (g->strt.nuse < g->strt.size / 4)  /* string table too big? */
+      luaS_resize(L, g->strt.size / 2);  /* shrink it a little */
+  }
 }
 
 
@@ -1171,7 +1176,7 @@ static lu_mem singlestep (lua_State *L) {
     }
     case GCSswpend: {  /* finish sweeps */
       makewhite(g, obj2gco(g->mainthread));  /* sweep main thread */
-      checkBuffer(L);
+      checkSizes(L, g);
       g->gcstate = GCSpause;  /* finish collection */
       return GCSWEEPCOST;
     }

+ 1 - 3
lstring.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstring.c,v 2.34 2013/09/05 19:31:49 roberto Exp roberto $
+** $Id: lstring.c,v 2.35 2013/09/11 12:26:14 roberto Exp roberto $
 ** String table (keeps all strings handled by Lua)
 ** See Copyright Notice in lua.h
 */
@@ -118,8 +118,6 @@ LUAI_FUNC void luaS_remove (lua_State *L, TString *ts) {
     p = &(*p)->tsv.hnext;
   *p = (*p)->tsv.hnext;  /* remove element from its list */
   tb->nuse--;
-  if (tb->nuse < tb->size/4)
-    luaS_resize(L, tb->size/2);
 }