** If stack size is more than 3 times the current use, reduce that size ** to twice the current use. (So, the final stack size is at most 2/3 the ** previous size, and half of its entries are empty.) ** As a particular case, if stack was handling a stack overflow and now ** it is not, 'max' (limited by LUAI_MAXSTACK) will be smaller than ** stacksize (equal to ERRORSTACKSIZE in this case), and so
| 298 | ** will be reduced to a "regular" size. |
| 299 | */ |
| 300 | void luaD_shrinkstack (lua_State *L) { |
| 301 | int inuse = stackinuse(L); |
| 302 | int max = (inuse > LUAI_MAXSTACK / 3) ? LUAI_MAXSTACK : inuse * 3; |
| 303 | /* if thread is currently not handling a stack overflow and its |
| 304 | size is larger than maximum "reasonable" size, shrink it */ |
| 305 | if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) { |
| 306 | int nsize = (inuse > LUAI_MAXSTACK / 2) ? LUAI_MAXSTACK : inuse * 2; |
| 307 | luaD_reallocstack(L, nsize, 0); /* ok if that fails */ |
| 308 | } |
| 309 | else /* don't change stack */ |
| 310 | condmovestack(L,{},{}); /* (change only for debugging) */ |
| 311 | luaE_shrinkCI(L); /* shrink CI list */ |
| 312 | } |
| 313 | |
| 314 | |
| 315 | void luaD_inctop (lua_State *L) { |
no test coverage detected