MCPcopy Create free account
hub / github.com/F-Stack/f-stack / luaS_resize

Function luaS_resize

freebsd/contrib/openzfs/module/lua/lstring.c:63–91  ·  view source on GitHub ↗

** resizes the string table */

Source from the content-addressed store, hash-verified

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

Callers 3

f_luaopenFunction · 0.70
newshrstrFunction · 0.70
checkSizesFunction · 0.70

Calls 2

luaC_runtilstateFunction · 0.85
bitmaskClass · 0.50

Tested by

no test coverage detected