Joined common code in 'lua_rawset' and 'lua_rawsetp'

This commit is contained in:
Roberto Ierusalimschy
2019-12-17 15:45:13 -03:00
parent e0ab13c62f
commit c646e57fd6
3 changed files with 25 additions and 23 deletions

35
lapi.c
View File

@@ -848,21 +848,33 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
}
LUA_API void lua_rawset (lua_State *L, int idx) {
static void aux_rawset (lua_State *L, int idx, TValue *key, int n) {
Table *t;
TValue *slot;
lua_lock(L);
api_checknelems(L, 2);
api_checknelems(L, n);
t = gettable(L, idx);
slot = luaH_set(L, t, s2v(L->top - 2));
slot = luaH_set(L, t, key);
setobj2t(L, slot, s2v(L->top - 1));
L->top -= n;
invalidateTMcache(t);
luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
L->top -= 2;
lua_unlock(L);
}
LUA_API void lua_rawset (lua_State *L, int idx) {
aux_rawset(L, idx, s2v(L->top - 2), 2);
}
LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
TValue k;
setpvalue(&k, cast_voidp(p));
aux_rawset(L, idx, &k, 1);
}
LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
Table *t;
lua_lock(L);
@@ -875,21 +887,6 @@ LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
}
LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
Table *t;
TValue k, *slot;
lua_lock(L);
api_checknelems(L, 1);
t = gettable(L, idx);
setpvalue(&k, cast_voidp(p));
slot = luaH_set(L, t, &k);
setobj2t(L, slot, s2v(L->top - 1));
luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
L->top--;
lua_unlock(L);
}
LUA_API int lua_setmetatable (lua_State *L, int objindex) {
TValue *obj;
Table *mt;