diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2025-08-09 15:08:53 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2025-08-09 15:08:53 -0300 |
| commit | 5b179eaf6a78af5f000d76147af94669d04487b2 (patch) | |
| tree | a3466ed22def25294ff1647d1af91cd4ef7fa567 /lcode.c | |
| parent | 8fddca81e7d4137512e92f398ca638d61b935dbd (diff) | |
| download | lua-5b179eaf6a78af5f000d76147af94669d04487b2.tar.gz lua-5b179eaf6a78af5f000d76147af94669d04487b2.tar.bz2 lua-5b179eaf6a78af5f000d76147af94669d04487b2.zip | |
Details
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 29 |
1 files changed, 15 insertions, 14 deletions
| @@ -565,20 +565,20 @@ static int k2proto (FuncState *fs, TValue *key, TValue *v) { | |||
| 565 | TValue val; | 565 | TValue val; |
| 566 | Proto *f = fs->f; | 566 | Proto *f = fs->f; |
| 567 | int tag = luaH_get(fs->kcache, key, &val); /* query scanner table */ | 567 | int tag = luaH_get(fs->kcache, key, &val); /* query scanner table */ |
| 568 | int k; | ||
| 569 | if (!tagisempty(tag)) { /* is there an index there? */ | 568 | if (!tagisempty(tag)) { /* is there an index there? */ |
| 570 | k = cast_int(ivalue(&val)); | 569 | int k = cast_int(ivalue(&val)); |
| 571 | /* collisions can happen only for float keys */ | 570 | /* collisions can happen only for float keys */ |
| 572 | lua_assert(ttisfloat(key) || luaV_rawequalobj(&f->k[k], v)); | 571 | lua_assert(ttisfloat(key) || luaV_rawequalobj(&f->k[k], v)); |
| 573 | return k; /* reuse index */ | 572 | return k; /* reuse index */ |
| 574 | } | 573 | } |
| 575 | /* constant not found; create a new entry */ | 574 | else { /* constant not found; create a new entry */ |
| 576 | k = addk(fs, f, v); | 575 | int k = addk(fs, f, v); |
| 577 | /* cache it for reuse; numerical value does not need GC barrier; | 576 | /* cache it for reuse; numerical value does not need GC barrier; |
| 578 | table is not a metatable, so it does not need to invalidate cache */ | 577 | table is not a metatable, so it does not need to invalidate cache */ |
| 579 | setivalue(&val, k); | 578 | setivalue(&val, k); |
| 580 | luaH_set(fs->ls->L, fs->kcache, key, &val); | 579 | luaH_set(fs->ls->L, fs->kcache, key, &val); |
| 581 | return k; | 580 | return k; |
| 581 | } | ||
| 582 | } | 582 | } |
| 583 | 583 | ||
| 584 | 584 | ||
| @@ -604,13 +604,14 @@ static int luaK_intK (FuncState *fs, lua_Integer n) { | |||
| 604 | /* | 604 | /* |
| 605 | ** Add a float to list of constants and return its index. Floats | 605 | ** Add a float to list of constants and return its index. Floats |
| 606 | ** with integral values need a different key, to avoid collision | 606 | ** with integral values need a different key, to avoid collision |
| 607 | ** with actual integers. To that, we add to the number its smaller | 607 | ** with actual integers. To that end, we add to the number its smaller |
| 608 | ** power-of-two fraction that is still significant in its scale. | 608 | ** power-of-two fraction that is still significant in its scale. |
| 609 | ** For doubles, that would be 1/2^52. | 609 | ** (For doubles, the fraction would be 2^-52). |
| 610 | ** This method is not bulletproof: different numbers may generate the | 610 | ** This method is not bulletproof: different numbers may generate the |
| 611 | ** same key (e.g., very large numbers will overflow to 'inf') and for | 611 | ** same key (e.g., very large numbers will overflow to 'inf') and for |
| 612 | ** floats larger than 2^53 the result is still an integer. At worst, | 612 | ** floats larger than 2^53 the result is still an integer. For those |
| 613 | ** this only wastes an entry with a duplicate. | 613 | ** cases, just generate a new entry. At worst, this only wastes an entry |
| 614 | ** with a duplicate. | ||
| 614 | */ | 615 | */ |
| 615 | static int luaK_numberK (FuncState *fs, lua_Number r) { | 616 | static int luaK_numberK (FuncState *fs, lua_Number r) { |
| 616 | TValue o, kv; | 617 | TValue o, kv; |
| @@ -625,7 +626,7 @@ static int luaK_numberK (FuncState *fs, lua_Number r) { | |||
| 625 | const lua_Number k = r * (1 + q); /* key */ | 626 | const lua_Number k = r * (1 + q); /* key */ |
| 626 | lua_Integer ik; | 627 | lua_Integer ik; |
| 627 | setfltvalue(&kv, k); /* key as a TValue */ | 628 | setfltvalue(&kv, k); /* key as a TValue */ |
| 628 | if (!luaV_flttointeger(k, &ik, F2Ieq)) { /* not an integral value? */ | 629 | if (!luaV_flttointeger(k, &ik, F2Ieq)) { /* not an integer value? */ |
| 629 | int n = k2proto(fs, &kv, &o); /* use key */ | 630 | int n = k2proto(fs, &kv, &o); /* use key */ |
| 630 | if (luaV_rawequalobj(&fs->f->k[n], &o)) /* correct value? */ | 631 | if (luaV_rawequalobj(&fs->f->k[n], &o)) /* correct value? */ |
| 631 | return n; | 632 | return n; |
