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

Function luaS_new

third-party/lua-5.5.0/src/lstring.c:269–283  ·  view source on GitHub ↗

** Create or reuse a zero-terminated string, first checking in the ** cache (using the string address as a key). The cache can contain ** only zero-terminated strings, so it is safe to use 'strcmp' to ** check hits. */

Source from the content-addressed store, hash-verified

267** check hits.
268*/
269TString *luaS_new (lua_State *L, const char *str) {
270 unsigned int i = point2uint(str) % STRCACHE_N; /* hash */
271 int j;
272 TString **p = G(L)->strcache[i];
273 for (j = 0; j < STRCACHE_M; j++) {
274 if (strcmp(str, getstr(p[j])) == 0) /* hit? */
275 return p[j]; /* that is it */
276 }
277 /* normal route */
278 for (j = STRCACHE_M - 1; j > 0; j--)
279 p[j] = p[j - 1]; /* move out last element */
280 /* new element is first in the list */
281 p[0] = luaS_newlstr(L, str, strlen(str));
282 return p[0];
283}
284
285
286Udata *luaS_newudata (lua_State *L, size_t s, unsigned short nuvalue) {

Callers 15

luaX_initFunction · 0.70
luaT_initFunction · 0.70
luaT_objtypenameFunction · 0.70
createvarargtabFunction · 0.70
getnumargsFunction · 0.70
luaY_parserFunction · 0.70
resume_errorFunction · 0.70
lua_pushlstringFunction · 0.70
lua_pushstringFunction · 0.70
auxgetstrFunction · 0.70
auxsetstrFunction · 0.70
luaV_tostringFunction · 0.50

Calls 1

luaS_newlstrFunction · 0.70

Tested by

no test coverage detected