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

Function addk

ThirdParty/lua/lua/lcode.c:312–336  ·  view source on GitHub ↗

** Use scanner's table to cache position of constants in constant list ** and try to reuse constants */

Source from the content-addressed store, hash-verified

310** and try to reuse constants
311*/
312static int addk (FuncState *fs, TValue *key, TValue *v) {
313 lua_State *L = fs->ls->L;
314 Proto *f = fs->f;
315 TValue *idx = luaH_set(L, fs->ls->h, key); /* index scanner table */
316 int k, oldsize;
317 if (ttisinteger(idx)) { /* is there an index there? */
318 k = cast_int(ivalue(idx));
319 /* correct value? (warning: must distinguish floats from integers!) */
320 if (k < fs->nk && ttype(&f->k[k]) == ttype(v) &&
321 luaV_rawequalobj(&f->k[k], v))
322 return k; /* reuse index */
323 }
324 /* constant not found; create a new entry */
325 oldsize = f->sizek;
326 k = fs->nk;
327 /* numerical value does not need GC barrier;
328 table has no metatable, so it does not need to invalidate cache */
329 setivalue(idx, k);
330 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
331 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
332 setobj(L, &f->k[k], v);
333 fs->nk++;
334 luaC_barrier(L, f, v);
335 return k;
336}
337
338
339int luaK_stringK (FuncState *fs, TString *s) {

Callers 5

luaK_stringKFunction · 0.85
luaK_intKFunction · 0.85
luaK_numberKFunction · 0.85
boolKFunction · 0.85
nilKFunction · 0.85

Calls 1

luaH_setFunction · 0.85

Tested by

no test coverage detected