MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / luaS_resize

Function luaS_resize

Source/Misc/lua/src/lua.c:9151–9176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9149
9150
9151void luaS_resize (lua_State *L, int newsize) {
9152GCObject **newhash;
9153stringtable *tb;
9154int i;
9155if (G(L)->gcstate == GCSsweepstring)
9156return; /* cannot resize during GC traverse */
9157newhash = luaM_newvector(L, newsize, GCObject *);
9158tb = &G(L)->strt;
9159for (i=0; i<newsize; i++) newhash[i] = NULL;
9160/* rehash */
9161for (i=0; i<tb->size; i++) {
9162GCObject *p = tb->hash[i];
9163while (p) { /* for each node in the list */
9164GCObject *next = p->gch.next; /* save next */
9165unsigned int h = gco2ts(p)->hash;
9166int h1 = lmod(h, newsize); /* new position */
9167lua_assert(cast_int(h%newsize) == lmod(h, newsize));
9168p->gch.next = newhash[h1]; /* chain it */
9169newhash[h1] = p;
9170p = next;
9171}
9172}
9173luaM_freearray(L, tb->hash, tb->size, TString *);
9174tb->size = newsize;
9175tb->hash = newhash;
9176}
9177
9178
9179static TString *newlstr (lua_State *L, const char *str, size_t l,

Callers 3

checkSizesFunction · 0.85
f_luaopenFunction · 0.85
newlstrFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected