MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaS_new

Function luaS_new

lib/lua/src/lstring.c:242–256  ·  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

240** check hits.
241*/
242TString *luaS_new (lua_State *L, const char *str) {
243 unsigned int i = point2uint(str) % STRCACHE_N; /* hash */
244 int j;
245 TString **p = G(L)->strcache[i];
246 for (j = 0; j < STRCACHE_M; j++) {
247 if (strcmp(str, getstr(p[j])) == 0) /* hit? */
248 return p[j]; /* that is it */
249 }
250 /* normal route */
251 for (j = STRCACHE_M - 1; j > 0; j--)
252 p[j] = p[j - 1]; /* move out last element */
253 /* new element is first in the list */
254 p[0] = luaS_newlstr(L, str, strlen(str));
255 return p[0];
256}
257
258
259Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue) {

Callers 9

luaX_initFunction · 0.85
luaT_initFunction · 0.85
luaT_objtypenameFunction · 0.85
luaY_parserFunction · 0.85
resume_errorFunction · 0.85
lua_pushlstringFunction · 0.85
lua_pushstringFunction · 0.85
auxgetstrFunction · 0.85
auxsetstrFunction · 0.85

Calls 2

luaS_newlstrFunction · 0.85
GFunction · 0.50

Tested by

no test coverage detected