From 4c6dfc342b026a51bfe3e2d56b1032fb670a2577 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 17 Sep 2013 12:40:06 -0300 Subject: CallInfo lists shrinks together with their associated stacks --- lstate.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lstate.c') diff --git a/lstate.c b/lstate.c index 0c3eb8f1..eab904fc 100644 --- a/lstate.c +++ b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.113 2013/09/11 14:09:55 roberto Exp roberto $ +** $Id: lstate.c,v 2.114 2013/09/13 16:21:52 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -119,6 +119,9 @@ CallInfo *luaE_extendCI (lua_State *L) { } +/* +** free all CallInfo structures not in use by a thread +*/ void luaE_freeCI (lua_State *L) { CallInfo *ci = L->ci; CallInfo *next = ci->next; @@ -130,6 +133,22 @@ void luaE_freeCI (lua_State *L) { } +/* +** free half of the CallInfo structures not in use by a thread +*/ +void luaE_shrinkCI (lua_State *L) { + CallInfo *ci = L->ci; + while (ci->next != NULL) { /* while there is 'next' */ + CallInfo *next2 = ci->next->next; /* next's next */ + if (next2 == NULL) break; + luaM_free(L, ci->next); /* remove next */ + ci->next = next2; /* remove 'next' from the list */ + next2->previous = ci; + ci = next2; + } +} + + static void stack_init (lua_State *L1, lua_State *L) { int i; CallInfo *ci; /* initialize stack array */ -- cgit v1.2.3-55-g6feb