MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaS_resize

Function luaS_resize

third-party/lua-5.2.4/src/lstring.c:64–92  ·  view source on GitHub ↗

** resizes the string table */

Source from the content-addressed store, hash-verified

62** resizes the string table
63*/
64void luaS_resize (lua_State *L, int newsize) {
65 int i;
66 stringtable *tb = &G(L)->strt;
67 /* cannot resize while GC is traversing strings */
68 luaC_runtilstate(L, ~bitmask(GCSsweepstring));
69 if (newsize > tb->size) {
70 luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
71 for (i = tb->size; i < newsize; i++) tb->hash[i] = NULL;
72 }
73 /* rehash */
74 for (i=0; i<tb->size; i++) {
75 GCObject *p = tb->hash[i];
76 tb->hash[i] = NULL;
77 while (p) { /* for each node in the list */
78 GCObject *next = gch(p)->next; /* save next */
79 unsigned int h = lmod(gco2ts(p)->hash, newsize); /* new position */
80 gch(p)->next = tb->hash[h]; /* chain it */
81 tb->hash[h] = p;
82 resetoldbit(p); /* see MOVE OLD rule */
83 p = next;
84 }
85 }
86 if (newsize < tb->size) {
87 /* shrinking slice must be empty */
88 lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);
89 luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
90 }
91 tb->size = newsize;
92}
93
94
95/*

Callers 3

f_luaopenFunction · 0.70
newshrstrFunction · 0.70
checkSizesFunction · 0.70

Calls 1

luaC_runtilstateFunction · 0.70

Tested by

no test coverage detected