** Use scanner's table to cache position of constants in constant list ** and try to reuse constants */
| 311 | ** and try to reuse constants |
| 312 | */ |
| 313 | static 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 | |
| 340 | int luaK_stringK(FuncState *fs, TString *s) { |
no test coverage detected