** Resize the string table. If allocation fails, keep the current size. ** (This can degrade performance, but any non-zero size should work ** correctly.) */
| 95 | ** correctly.) |
| 96 | */ |
| 97 | void luaS_resize (lua_State *L, int nsize) { |
| 98 | stringtable *tb = &G(L)->strt; |
| 99 | int osize = tb->size; |
| 100 | TString **newvect; |
| 101 | if (nsize < osize) /* shrinking table? */ |
| 102 | tablerehash(tb->hash, osize, nsize); /* depopulate shrinking part */ |
| 103 | newvect = luaM_reallocvector(L, tb->hash, osize, nsize, TString*); |
| 104 | if (unlikely(newvect == NULL)) { /* reallocation failed? */ |
| 105 | if (nsize < osize) /* was it shrinking table? */ |
| 106 | tablerehash(tb->hash, nsize, osize); /* restore to original size */ |
| 107 | /* leave table as it was */ |
| 108 | } |
| 109 | else { /* allocation succeeded */ |
| 110 | tb->hash = newvect; |
| 111 | tb->size = nsize; |
| 112 | if (nsize > osize) |
| 113 | tablerehash(newvect, osize, nsize); /* rehash for new size */ |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | |
| 118 | /* |
no test coverage detected