Some details in 'lmem.c' and 'lgc.c'

- Several new comments in 'lmem.c'.
- Both 'luaM_growaux_' and 'luaM_shrinkvector_' use 'luaM_saferealloc_'
  to check for errors. Moreover, the use of 'luaM_saferealloc_' makes
  'luaM_shrinkvector_' try again if shrink fails (which can happen now).
- In 'checkSizes', save old debt only when needed.
This commit is contained in:
Roberto Ierusalimschy
2019-07-19 09:43:35 -03:00
parent 3c1d415bd3
commit 9cdf6b7082
2 changed files with 42 additions and 27 deletions

7
lgc.c
View File

@@ -794,10 +794,11 @@ static GCObject **sweeptolive (lua_State *L, GCObject **p) {
*/
static void checkSizes (lua_State *L, global_State *g) {
if (!g->gcemergency) {
l_mem olddebt = g->GCdebt;
if (g->strt.nuse < g->strt.size / 4) /* string table too big? */
if (g->strt.nuse < g->strt.size / 4) { /* string table too big? */
l_mem olddebt = g->GCdebt;
luaS_resize(L, g->strt.size / 2);
g->GCestimate += g->GCdebt - olddebt; /* correct estimate */
g->GCestimate += g->GCdebt - olddebt; /* correct estimate */
}
}
}