** Resize the string table. If allocation fails, keep the current size. ** (This can degrade performance, but any non-zero size should work ** correctly.) */
| 83 | ** correctly.) |
| 84 | */ |
| 85 | void luaS_resize (lua_State *L, int nsize) { |
| 86 | stringtable *tb = &G(L)->strt; |
| 87 | int osize = tb->size; |
| 88 | TString **newvect; |
| 89 | if (nsize < osize) /* shrinking table? */ |
| 90 | tablerehash(tb->hash, osize, nsize); /* depopulate shrinking part */ |
| 91 | newvect = luaM_reallocvector(L, tb->hash, osize, nsize, TString*); |
| 92 | if (l_unlikely(newvect == NULL)) { /* reallocation failed? */ |
| 93 | if (nsize < osize) /* was it shrinking table? */ |
| 94 | tablerehash(tb->hash, nsize, osize); /* restore to original size */ |
| 95 | /* leave table as it was */ |
| 96 | } |
| 97 | else { /* allocation succeeded */ |
| 98 | tb->hash = newvect; |
| 99 | tb->size = nsize; |
| 100 | if (nsize > osize) |
| 101 | tablerehash(newvect, osize, nsize); /* rehash for new size */ |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | |
| 106 | /* |
no test coverage detected