** 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 MAXSTACK) will be smaller than ** stacksize (equal to ERRORSTACKSIZE in this case), and so the s
| 409 | ** will be reduced to a "regular" size. |
| 410 | */ |
| 411 | void luaD_shrinkstack (lua_State *L) { |
| 412 | int inuse = stackinuse(L); |
| 413 | int max = (inuse > MAXSTACK / 3) ? MAXSTACK : inuse * 3; |
| 414 | /* if thread is currently not handling a stack overflow and its |
| 415 | size is larger than maximum "reasonable" size, shrink it */ |
| 416 | if (inuse <= MAXSTACK && stacksize(L) > max) { |
| 417 | int nsize = (inuse > MAXSTACK / 2) ? MAXSTACK : inuse * 2; |
| 418 | luaD_reallocstack(L, nsize, 0); /* ok if that fails */ |
| 419 | } |
| 420 | else /* don't change stack */ |
| 421 | condmovestack(L,(void)0,(void)0); /* (change only for debugging) */ |
| 422 | luaE_shrinkCI(L); /* shrink CI list */ |
| 423 | } |
| 424 | |
| 425 | |
| 426 | void luaD_inctop (lua_State *L) { |
no test coverage detected