aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-09-09 10:45:50 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-09-09 10:45:50 -0300
commit364cdbdbdbc1b5e88b1795460a09ea7f4a73a86b (patch)
tree35ef24395742bcea5bd7efe190b433f24b6a2753
parentb91bc93fd33f2158745b37c9e091c6fa4d1a4fd5 (diff)
downloadlua-364cdbdbdbc1b5e88b1795460a09ea7f4a73a86b.tar.gz
lua-364cdbdbdbc1b5e88b1795460a09ea7f4a73a86b.tar.bz2
lua-364cdbdbdbc1b5e88b1795460a09ea7f4a73a86b.zip
'setobj2t' incorporated into 'luaV_fastset' + 'invalidateTMcache'
is not needed in the fast track (as it does not create new entries) + small bug in 'auxsetstr' (calling barrier with wrong object) + using 'setobj2t' without side effects in its arguments
-rw-r--r--lapi.c47
1 files changed, 21 insertions, 26 deletions
diff --git a/lapi.c b/lapi.c
index bd4efaa3..63258055 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.253 2015/08/03 20:40:26 roberto Exp roberto $ 2** $Id: lapi.c,v 2.254 2015/08/25 18:50:37 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*/
@@ -736,28 +736,28 @@ LUA_API int lua_getuservalue (lua_State *L, int idx) {
736** set functions (stack -> Lua) 736** set functions (stack -> Lua)
737*/ 737*/
738 738
739/*
740** t[k] = value at the top of the stack (where 'k' is a string)
741*/
739static void auxsetstr (lua_State *L, const TValue *t, const char *k) { 742static void auxsetstr (lua_State *L, const TValue *t, const char *k) {
740 const TValue *aux; 743 const TValue *aux;
741 TString *str = luaS_new(L, k); 744 TString *str = luaS_new(L, k);
742 api_checknelems(L, 1); 745 api_checknelems(L, 1);
743 if (luaV_fastset(L, t, str, aux, luaH_getstr, L->top)) { 746 if (luaV_fastset(L, t, str, aux, luaH_getstr, L->top - 1))
744 invalidateTMcache(hvalue(t));
745 setobj2t(L, cast(TValue *, aux), L->top - 1);
746 L->top--; /* pop value */ 747 L->top--; /* pop value */
747 }
748 else { 748 else {
749 setsvalue2s(L, L->top, str); 749 setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */
750 api_incr_top(L); 750 api_incr_top(L);
751 luaV_finishset(L, t, L->top - 1, L->top - 2, aux); 751 luaV_finishset(L, t, L->top - 1, L->top - 2, aux);
752 L->top -= 2; /* pop value and key */ 752 L->top -= 2; /* pop value and key */
753 } 753 }
754 lua_unlock(L); 754 lua_unlock(L); /* lock done by caller */
755} 755}
756 756
757 757
758LUA_API void lua_setglobal (lua_State *L, const char *name) { 758LUA_API void lua_setglobal (lua_State *L, const char *name) {
759 Table *reg = hvalue(&G(L)->l_registry); 759 Table *reg = hvalue(&G(L)->l_registry);
760 lua_lock(L); 760 lua_lock(L); /* unlock done in 'auxsetstr' */
761 auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name); 761 auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);
762} 762}
763 763
@@ -774,7 +774,7 @@ LUA_API void lua_settable (lua_State *L, int idx) {
774 774
775 775
776LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { 776LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
777 lua_lock(L); 777 lua_lock(L); /* unlock done in 'auxsetstr' */
778 auxsetstr(L, index2addr(L, idx), k); 778 auxsetstr(L, index2addr(L, idx), k);
779} 779}
780 780
@@ -785,10 +785,8 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
785 lua_lock(L); 785 lua_lock(L);
786 api_checknelems(L, 1); 786 api_checknelems(L, 1);
787 t = index2addr(L, idx); 787 t = index2addr(L, idx);
788 if (luaV_fastset(L, t, n, aux, luaH_getint, L->top - 1)) { 788 if (luaV_fastset(L, t, n, aux, luaH_getint, L->top - 1))
789 setobj2t(L, cast(TValue *, aux), L->top - 1);
790 L->top--; /* pop value */ 789 L->top--; /* pop value */
791 }
792 else { 790 else {
793 setivalue(L->top, n); 791 setivalue(L->top, n);
794 api_incr_top(L); 792 api_incr_top(L);
@@ -801,15 +799,15 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
801 799
802LUA_API void lua_rawset (lua_State *L, int idx) { 800LUA_API void lua_rawset (lua_State *L, int idx) {
803 StkId o; 801 StkId o;
804 Table *t; 802 TValue *slot;
805 lua_lock(L); 803 lua_lock(L);
806 api_checknelems(L, 2); 804 api_checknelems(L, 2);
807 o = index2addr(L, idx); 805 o = index2addr(L, idx);
808 api_check(L, ttistable(o), "table expected"); 806 api_check(L, ttistable(o), "table expected");
809 t = hvalue(o); 807 slot = luaH_set(L, hvalue(o), L->top - 2);
810 setobj2t(L, luaH_set(L, t, L->top-2), L->top-1); 808 setobj2t(L, slot, L->top - 1);
811 invalidateTMcache(t); 809 invalidateTMcache(hvalue(o));
812 luaC_barrierback(L, t, L->top-1); 810 luaC_barrierback(L, hvalue(o), L->top-1);
813 L->top -= 2; 811 L->top -= 2;
814 lua_unlock(L); 812 lua_unlock(L);
815} 813}
@@ -817,14 +815,12 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
817 815
818LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { 816LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
819 StkId o; 817 StkId o;
820 Table *t;
821 lua_lock(L); 818 lua_lock(L);
822 api_checknelems(L, 1); 819 api_checknelems(L, 1);
823 o = index2addr(L, idx); 820 o = index2addr(L, idx);
824 api_check(L, ttistable(o), "table expected"); 821 api_check(L, ttistable(o), "table expected");
825 t = hvalue(o); 822 luaH_setint(L, hvalue(o), n, L->top - 1);
826 luaH_setint(L, t, n, L->top - 1); 823 luaC_barrierback(L, hvalue(o), L->top-1);
827 luaC_barrierback(L, t, L->top-1);
828 L->top--; 824 L->top--;
829 lua_unlock(L); 825 lua_unlock(L);
830} 826}
@@ -832,16 +828,15 @@ LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
832 828
833LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { 829LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
834 StkId o; 830 StkId o;
835 Table *t; 831 TValue k, *slot;
836 TValue k;
837 lua_lock(L); 832 lua_lock(L);
838 api_checknelems(L, 1); 833 api_checknelems(L, 1);
839 o = index2addr(L, idx); 834 o = index2addr(L, idx);
840 api_check(L, ttistable(o), "table expected"); 835 api_check(L, ttistable(o), "table expected");
841 t = hvalue(o);
842 setpvalue(&k, cast(void *, p)); 836 setpvalue(&k, cast(void *, p));
843 setobj2t(L, luaH_set(L, t, &k), L->top - 1); 837 slot = luaH_set(L, hvalue(o), &k);
844 luaC_barrierback(L, t, L->top - 1); 838 setobj2t(L, slot, L->top - 1);
839 luaC_barrierback(L, hvalue(o), L->top - 1);
845 L->top--; 840 L->top--;
846 lua_unlock(L); 841 lua_unlock(L);
847} 842}