MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaS_resize

Function luaS_resize

depends/lua/src/lstring.c:71–96  ·  view source on GitHub ↗

** resizes the string table */

Source from the content-addressed store, hash-verified

69** resizes the string table
70*/
71void luaS_resize (lua_State *L, int newsize) {
72 int i;
73 stringtable *tb = &G(L)->strt;
74 if (newsize > tb->size) { /* grow table if needed */
75 luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);
76 for (i = tb->size; i < newsize; i++)
77 tb->hash[i] = NULL;
78 }
79 for (i = 0; i < tb->size; i++) { /* rehash */
80 TString *p = tb->hash[i];
81 tb->hash[i] = NULL;
82 while (p) { /* for each node in the list */
83 TString *hnext = p->u.hnext; /* save next */
84 unsigned int h = lmod(p->hash, newsize); /* new position */
85 p->u.hnext = tb->hash[h]; /* chain it */
86 tb->hash[h] = p;
87 p = hnext;
88 }
89 }
90 if (newsize < tb->size) { /* shrink table if needed */
91 /* vanishing slice should be empty */
92 lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);
93 luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);
94 }
95 tb->size = newsize;
96}
97
98
99/*

Callers 3

luaS_initFunction · 0.85
internshrstrFunction · 0.85
checkSizesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected