MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / luaS_resize

Function luaS_resize

extlibs/lua/src/lstring.c:97–115  ·  view source on GitHub ↗

** Resize the string table. If allocation fails, keep the current size. ** (This can degrade performance, but any non-zero size should work ** correctly.) */

Source from the content-addressed store, hash-verified

95** correctly.)
96*/
97void 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/*

Callers 2

growstrtabFunction · 0.85
checkSizesFunction · 0.85

Calls 1

tablerehashFunction · 0.85

Tested by

no test coverage detected