diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-15 17:56:25 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-15 17:56:25 -0300 |
| commit | 351ccd733298e08c41937c1baf22a68e62bfeca9 (patch) | |
| tree | be290db6b41e949c74d6699c7a01963c7cec9b21 /lapi.c | |
| parent | 6443185167c77adcc8552a3fee7edab7895db1a9 (diff) | |
| download | lua-351ccd733298e08c41937c1baf22a68e62bfeca9.tar.gz lua-351ccd733298e08c41937c1baf22a68e62bfeca9.tar.bz2 lua-351ccd733298e08c41937c1baf22a68e62bfeca9.zip | |
Towards a new implementation of arrays
The array part of a table wastes too much space, due to padding.
To avoid that, we need to store values in the array as something
different from a TValue. Therefore, the API for table access
should not assume that any value in a table lives in a *TValue.
This commit is the first step to remove that assumption: functions
luaH_get*, instead of returning a *TValue where the value lives,
receive a *TValue where to put the value being accessed.
(We still have to change the luaH_set* functions.)
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 32 |
1 files changed, 14 insertions, 18 deletions
| @@ -637,16 +637,16 @@ LUA_API int lua_pushthread (lua_State *L) { | |||
| 637 | 637 | ||
| 638 | 638 | ||
| 639 | l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) { | 639 | l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) { |
| 640 | const TValue *slot; | 640 | int aux; |
| 641 | TString *str = luaS_new(L, k); | 641 | TString *str = luaS_new(L, k); |
| 642 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { | 642 | luaV_fastget1(t, str, s2v(L->top.p), luaH_getstr1, aux); |
| 643 | setobj2s(L, L->top.p, slot); | 643 | if (aux == HOK) { |
| 644 | api_incr_top(L); | 644 | api_incr_top(L); |
| 645 | } | 645 | } |
| 646 | else { | 646 | else { |
| 647 | setsvalue2s(L, L->top.p, str); | 647 | setsvalue2s(L, L->top.p, str); |
| 648 | api_incr_top(L); | 648 | api_incr_top(L); |
| 649 | luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot); | 649 | luaV_finishget1(L, t, s2v(L->top.p - 1), L->top.p - 1, aux); |
| 650 | } | 650 | } |
| 651 | lua_unlock(L); | 651 | lua_unlock(L); |
| 652 | return ttype(s2v(L->top.p - 1)); | 652 | return ttype(s2v(L->top.p - 1)); |
| @@ -672,15 +672,13 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) { | |||
| 672 | 672 | ||
| 673 | 673 | ||
| 674 | LUA_API int lua_gettable (lua_State *L, int idx) { | 674 | LUA_API int lua_gettable (lua_State *L, int idx) { |
| 675 | const TValue *slot; | 675 | int aux; |
| 676 | TValue *t; | 676 | TValue *t; |
| 677 | lua_lock(L); | 677 | lua_lock(L); |
| 678 | t = index2value(L, idx); | 678 | t = index2value(L, idx); |
| 679 | if (luaV_fastget(L, t, s2v(L->top.p - 1), slot, luaH_get)) { | 679 | luaV_fastget1(t, s2v(L->top.p - 1), s2v(L->top.p - 1), luaH_get1, aux); |
| 680 | setobj2s(L, L->top.p - 1, slot); | 680 | if (aux != HOK) |
| 681 | } | 681 | luaV_finishget1(L, t, s2v(L->top.p - 1), L->top.p - 1, aux); |
| 682 | else | ||
| 683 | luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot); | ||
| 684 | lua_unlock(L); | 682 | lua_unlock(L); |
| 685 | return ttype(s2v(L->top.p - 1)); | 683 | return ttype(s2v(L->top.p - 1)); |
| 686 | } | 684 | } |
| @@ -694,16 +692,14 @@ LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { | |||
| 694 | 692 | ||
| 695 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | 693 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { |
| 696 | TValue *t; | 694 | TValue *t; |
| 697 | const TValue *slot; | 695 | int aux; |
| 698 | lua_lock(L); | 696 | lua_lock(L); |
| 699 | t = index2value(L, idx); | 697 | t = index2value(L, idx); |
| 700 | if (luaV_fastgeti(L, t, n, slot)) { | 698 | luaV_fastgeti1(t, n, s2v(L->top.p), aux); |
| 701 | setobj2s(L, L->top.p, slot); | 699 | if (aux != HOK) { |
| 702 | } | 700 | TValue key; |
| 703 | else { | 701 | setivalue(&key, n); |
| 704 | TValue aux; | 702 | luaV_finishget1(L, t, &key, L->top.p, aux); |
| 705 | setivalue(&aux, n); | ||
| 706 | luaV_finishget(L, t, &aux, L->top.p, slot); | ||
| 707 | } | 703 | } |
| 708 | api_incr_top(L); | 704 | api_incr_top(L); |
| 709 | lua_unlock(L); | 705 | lua_unlock(L); |
