MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / addk

Function addk

src/Chain/libraries/glua/lcode.cpp:313–337  ·  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

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