diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-11 15:57:46 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-11 15:57:46 -0300 |
| commit | 7647d5d13d016f114dac4be0b9da62d502eab400 (patch) | |
| tree | 7240a95fd732596e658648f6052b29e551a01265 /lapi.c | |
| parent | 7184f6343a0074d02f6f0e35654cfa55427710d3 (diff) | |
| download | lua-7647d5d13d016f114dac4be0b9da62d502eab400.tar.gz lua-7647d5d13d016f114dac4be0b9da62d502eab400.tar.bz2 lua-7647d5d13d016f114dac4be0b9da62d502eab400.zip | |
revamp of fast track for table access (table set uses the same
macros as table get + new macro for integer keys)
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 41 |
1 files changed, 26 insertions, 15 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.264 2017/04/20 18:22:44 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.265 2017/04/24 16:59:26 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -609,10 +609,15 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) { | |||
| 609 | 609 | ||
| 610 | 610 | ||
| 611 | LUA_API int lua_gettable (lua_State *L, int idx) { | 611 | LUA_API int lua_gettable (lua_State *L, int idx) { |
| 612 | const TValue *slot; | ||
| 612 | StkId t; | 613 | StkId t; |
| 613 | lua_lock(L); | 614 | lua_lock(L); |
| 614 | t = index2addr(L, idx); | 615 | t = index2addr(L, idx); |
| 615 | luaV_gettable(L, t, L->top - 1, L->top - 1); | 616 | if (luaV_fastget(L, t, L->top - 1, slot, luaH_get)) { |
| 617 | setobj2s(L, L->top - 1, slot); | ||
| 618 | } | ||
| 619 | else | ||
| 620 | luaV_finishget(L, t, L->top - 1, L->top - 1, slot); | ||
| 616 | lua_unlock(L); | 621 | lua_unlock(L); |
| 617 | return ttnov(L->top - 1); | 622 | return ttnov(L->top - 1); |
| 618 | } | 623 | } |
| @@ -629,15 +634,15 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | |||
| 629 | const TValue *slot; | 634 | const TValue *slot; |
| 630 | lua_lock(L); | 635 | lua_lock(L); |
| 631 | t = index2addr(L, idx); | 636 | t = index2addr(L, idx); |
| 632 | if (luaV_fastget(L, t, n, slot, luaH_getint)) { | 637 | if (luaV_fastgeti(L, t, n, slot)) { |
| 633 | setobj2s(L, L->top, slot); | 638 | setobj2s(L, L->top, slot); |
| 634 | api_incr_top(L); | ||
| 635 | } | 639 | } |
| 636 | else { | 640 | else { |
| 637 | setivalue(L->top, n); | 641 | TValue aux; |
| 638 | api_incr_top(L); | 642 | setivalue(&aux, n); |
| 639 | luaV_finishget(L, t, L->top - 1, L->top - 1, slot); | 643 | luaV_finishget(L, t, &aux, L->top, slot); |
| 640 | } | 644 | } |
| 645 | api_incr_top(L); | ||
| 641 | lua_unlock(L); | 646 | lua_unlock(L); |
| 642 | return ttnov(L->top - 1); | 647 | return ttnov(L->top - 1); |
| 643 | } | 648 | } |
| @@ -743,8 +748,10 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) { | |||
| 743 | const TValue *slot; | 748 | const TValue *slot; |
| 744 | TString *str = luaS_new(L, k); | 749 | TString *str = luaS_new(L, k); |
| 745 | api_checknelems(L, 1); | 750 | api_checknelems(L, 1); |
| 746 | if (luaV_fastset(L, t, str, slot, luaH_getstr, L->top - 1)) | 751 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { |
| 752 | luaV_finishfastset(L, t, slot, L->top - 1); | ||
| 747 | L->top--; /* pop value */ | 753 | L->top--; /* pop value */ |
| 754 | } | ||
| 748 | else { | 755 | else { |
| 749 | setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ | 756 | setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ |
| 750 | api_incr_top(L); | 757 | api_incr_top(L); |
| @@ -764,10 +771,14 @@ LUA_API void lua_setglobal (lua_State *L, const char *name) { | |||
| 764 | 771 | ||
| 765 | LUA_API void lua_settable (lua_State *L, int idx) { | 772 | LUA_API void lua_settable (lua_State *L, int idx) { |
| 766 | StkId t; | 773 | StkId t; |
| 774 | const TValue *slot; | ||
| 767 | lua_lock(L); | 775 | lua_lock(L); |
| 768 | api_checknelems(L, 2); | 776 | api_checknelems(L, 2); |
| 769 | t = index2addr(L, idx); | 777 | t = index2addr(L, idx); |
| 770 | luaV_settable(L, t, L->top - 2, L->top - 1); | 778 | if (luaV_fastget(L, t, L->top - 2, slot, luaH_get)) |
| 779 | luaV_finishfastset(L, t, slot, L->top - 1); | ||
| 780 | else | ||
| 781 | luaV_finishset(L, t, L->top - 2, L->top - 1, slot); | ||
| 771 | L->top -= 2; /* pop index and value */ | 782 | L->top -= 2; /* pop index and value */ |
| 772 | lua_unlock(L); | 783 | lua_unlock(L); |
| 773 | } | 784 | } |
| @@ -785,14 +796,14 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | |||
| 785 | lua_lock(L); | 796 | lua_lock(L); |
| 786 | api_checknelems(L, 1); | 797 | api_checknelems(L, 1); |
| 787 | t = index2addr(L, idx); | 798 | t = index2addr(L, idx); |
| 788 | if (luaV_fastset(L, t, n, slot, luaH_getint, L->top - 1)) | 799 | if (luaV_fastgeti(L, t, n, slot)) |
| 789 | L->top--; /* pop value */ | 800 | luaV_finishfastset(L, t, slot, L->top - 1); |
| 790 | else { | 801 | else { |
| 791 | setivalue(L->top, n); | 802 | TValue aux; |
| 792 | api_incr_top(L); | 803 | setivalue(&aux, n); |
| 793 | luaV_finishset(L, t, L->top - 1, L->top - 2, slot); | 804 | luaV_finishset(L, t, &aux, L->top - 1, slot); |
| 794 | L->top -= 2; /* pop value and key */ | ||
| 795 | } | 805 | } |
| 806 | L->top--; /* pop value */ | ||
| 796 | lua_unlock(L); | 807 | lua_unlock(L); |
| 797 | } | 808 | } |
| 798 | 809 | ||
