MCPcopy Create free account
hub / github.com/BigPig0/RelayLive / internshrstr

Function internshrstr

ThirdParty/lua/lua/lstring.c:122–145  ·  view source on GitHub ↗

** checks whether short string exists and reuses it or creates a new one */

Source from the content-addressed store, hash-verified

120** checks whether short string exists and reuses it or creates a new one
121*/
122static TString *internshrstr (lua_State *L, const char *str, size_t l) {
123 TString *ts;
124 global_State *g = G(L);
125 unsigned int h = luaS_hash(str, l, g->seed);
126 TString **list = &g->strt.hash[lmod(h, g->strt.size)];
127 for (ts = *list; ts != NULL; ts = ts->hnext) {
128 if (l == ts->len &&
129 (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {
130 /* found! */
131 if (isdead(g, ts)) /* dead (but not collected yet)? */
132 changewhite(ts); /* resurrect it */
133 return ts;
134 }
135 }
136 if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) {
137 luaS_resize(L, g->strt.size * 2);
138 list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */
139 }
140 ts = createstrobj(L, str, l, LUA_TSHRSTR, h);
141 ts->hnext = *list;
142 *list = ts;
143 g->strt.nuse++;
144 return ts;
145}
146
147
148/*

Callers 1

luaS_newlstrFunction · 0.85

Calls 4

luaS_hashFunction · 0.85
luaS_resizeFunction · 0.85
createstrobjFunction · 0.85
GFunction · 0.50

Tested by

no test coverage detected