diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-08-03 16:50:49 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-08-03 16:50:49 -0300 |
commit | 3b795541c488c7e633567897c9112312007a20a0 (patch) | |
tree | baa671c28bef6a13def34e5872fb81594a168861 /lapi.c | |
parent | 20b9e594419787cceaa04c645e485b13a2a9f4dc (diff) | |
download | lua-3b795541c488c7e633567897c9112312007a20a0.tar.gz lua-3b795541c488c7e633567897c9112312007a20a0.tar.bz2 lua-3b795541c488c7e633567897c9112312007a20a0.zip |
fast track for 'settable'
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 52 |
1 files changed, 31 insertions, 21 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.250 2015/06/18 14:19:52 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.251 2015/07/20 18:24:50 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 | */ |
@@ -731,18 +731,28 @@ LUA_API int lua_getuservalue (lua_State *L, int idx) { | |||
731 | ** set functions (stack -> Lua) | 731 | ** set functions (stack -> Lua) |
732 | */ | 732 | */ |
733 | 733 | ||
734 | static void auxsetstr (lua_State *L, const TValue *t, const char *k) { | ||
735 | const TValue *aux; | ||
736 | TString *str = luaS_new(L, k); | ||
737 | api_checknelems(L, 1); | ||
738 | if (luaV_fastset(L, t, str, aux, luaH_getstr, L->top)) { | ||
739 | setobj2t(L, cast(TValue *, aux), L->top - 1); | ||
740 | L->top--; /* pop value */ | ||
741 | } | ||
742 | else { | ||
743 | setsvalue2s(L, L->top, str); | ||
744 | api_incr_top(L); | ||
745 | luaV_finishset(L, t, L->top - 1, L->top - 2, aux); | ||
746 | L->top -= 2; /* pop value and key */ | ||
747 | } | ||
748 | lua_unlock(L); | ||
749 | } | ||
750 | |||
734 | 751 | ||
735 | LUA_API void lua_setglobal (lua_State *L, const char *name) { | 752 | LUA_API void lua_setglobal (lua_State *L, const char *name) { |
736 | Table *reg = hvalue(&G(L)->l_registry); | 753 | Table *reg = hvalue(&G(L)->l_registry); |
737 | const TValue *gt; /* global table */ | ||
738 | lua_lock(L); | 754 | lua_lock(L); |
739 | api_checknelems(L, 1); | 755 | auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name); |
740 | gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | ||
741 | setsvalue2s(L, L->top, luaS_new(L, name)); | ||
742 | api_incr_top(L); | ||
743 | luaV_settable(L, gt, L->top - 1, L->top - 2); | ||
744 | L->top -= 2; /* pop value and key */ | ||
745 | lua_unlock(L); | ||
746 | } | 756 | } |
747 | 757 | ||
748 | 758 | ||
@@ -758,27 +768,27 @@ LUA_API void lua_settable (lua_State *L, int idx) { | |||
758 | 768 | ||
759 | 769 | ||
760 | LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { | 770 | LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { |
761 | StkId t; | ||
762 | lua_lock(L); | 771 | lua_lock(L); |
763 | api_checknelems(L, 1); | 772 | auxsetstr(L, index2addr(L, idx), k); |
764 | t = index2addr(L, idx); | ||
765 | setsvalue2s(L, L->top, luaS_new(L, k)); | ||
766 | api_incr_top(L); | ||
767 | luaV_settable(L, t, L->top - 1, L->top - 2); | ||
768 | L->top -= 2; /* pop value and key */ | ||
769 | lua_unlock(L); | ||
770 | } | 773 | } |
771 | 774 | ||
772 | 775 | ||
773 | LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | 776 | LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { |
774 | StkId t; | 777 | StkId t; |
778 | const TValue *aux; | ||
775 | lua_lock(L); | 779 | lua_lock(L); |
776 | api_checknelems(L, 1); | 780 | api_checknelems(L, 1); |
777 | t = index2addr(L, idx); | 781 | t = index2addr(L, idx); |
778 | setivalue(L->top, n); | 782 | if (luaV_fastset(L, t, n, aux, luaH_getint, L->top - 1)) { |
779 | api_incr_top(L); | 783 | setobj2t(L, cast(TValue *, aux), L->top - 1); |
780 | luaV_settable(L, t, L->top - 1, L->top - 2); | 784 | L->top--; /* pop value */ |
781 | L->top -= 2; /* pop value and key */ | 785 | } |
786 | else { | ||
787 | setivalue(L->top, n); | ||
788 | api_incr_top(L); | ||
789 | luaV_finishset(L, t, L->top - 1, L->top - 2, aux); | ||
790 | L->top -= 2; /* pop value and key */ | ||
791 | } | ||
782 | lua_unlock(L); | 792 | lua_unlock(L); |
783 | } | 793 | } |
784 | 794 | ||