simpler definition for 'setobj' (trust the compiler for the assignment)

This commit is contained in:
Roberto Ierusalimschy 2014-07-29 13:22:24 -03:00
parent 3ccbae84d2
commit 07c7fdb9df
4 changed files with 23 additions and 11 deletions

4
lgc.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lgc.c,v 2.190 2014/07/19 15:09:37 roberto Exp roberto $
** $Id: lgc.c,v 2.191 2014/07/19 15:14:46 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@ -112,7 +112,7 @@ static void reallymarkobject (global_State *g, GCObject *o);
static void removeentry (Node *n) {
lua_assert(ttisnil(gval(n)));
if (valiswhite(gkey(n)))
setdeadvalue(gkey(n)); /* unused and unmarked key; remove it */
setdeadvalue(wgkey(n)); /* unused and unmarked key; remove it */
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 2.98 2014/07/18 13:36:14 roberto Exp roberto $
** $Id: lobject.h,v 2.99 2014/07/18 14:46:47 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -241,8 +241,7 @@ typedef struct lua_TValue TValue;
#define setobj(L,obj1,obj2) \
{ const TValue *io2=(obj2); TValue *io1=(obj1); \
io1->value_ = io2->value_; io1->tt_ = io2->tt_; \
{ TValue *io1=(obj1); *io1 = *(obj2); \
(void)L; checkliveness(G(L),io1); }
@ -471,6 +470,13 @@ typedef union TKey {
} TKey;
/* copy a value into a key without messing up field 'next' */
#define setkey(L,key,obj) \
{ TKey *k_=(key); const TValue *io_=(obj); \
k_->nk.value_ = io_->value_; k_->nk.tt_ = io_->tt_; \
(void)L; checkliveness(G(L),io_); }
typedef struct Node {
TValue i_val;
TKey i_key;

View File

@ -1,5 +1,5 @@
/*
** $Id: ltable.c,v 2.91 2014/06/26 16:17:35 roberto Exp roberto $
** $Id: ltable.c,v 2.92 2014/07/18 13:36:14 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -309,7 +309,7 @@ static void setnodevector (lua_State *L, Table *t, int size) {
for (i=0; i<size; i++) {
Node *n = gnode(t, i);
gnext(n) = 0;
setnilvalue(gkey(n));
setnilvalue(wgkey(n));
setnilvalue(gval(n));
}
}
@ -466,7 +466,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
mp = f;
}
}
setobj2t(L, gkey(mp), key);
setkey(L, &mp->i_key, key);
luaC_barrierback(L, t, key);
lua_assert(ttisnil(gval(mp)));
return gval(mp);
@ -503,7 +503,8 @@ const TValue *luaH_getstr (Table *t, TString *key) {
Node *n = hashstr(t, key);
lua_assert(key->tt == LUA_TSHRSTR);
for (;;) { /* check whether `key' is somewhere in the chain */
if (ttisshrstring(gkey(n)) && eqshrstr(tsvalue(gkey(n)), key))
const TValue *k = gkey(n);
if (ttisshrstring(k) && eqshrstr(tsvalue(k), key))
return gval(n); /* that's it */
else {
int nx = gnext(n);

View File

@ -1,5 +1,5 @@
/*
** $Id: ltable.h,v 2.17 2013/04/26 15:39:25 roberto Exp roberto $
** $Id: ltable.h,v 2.18 2013/08/30 16:01:37 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -11,10 +11,15 @@
#define gnode(t,i) (&(t)->node[i])
#define gkey(n) (&(n)->i_key.tvk)
#define gval(n) (&(n)->i_val)
#define gnext(n) ((n)->i_key.nk.next)
/* 'const' to avoid wrong writings that can mess up field 'next' */
#define gkey(n) cast(const TValue*, (&(n)->i_key.tvk))
#define wgkey(n) (&(n)->i_key.nk)
#define invalidateTMcache(t) ((t)->flags = 0)