Prechádzať zdrojové kódy

Avoid taking the address of a 'TValue' field

That structure can be packed in the future.
Roberto Ierusalimschy 3 rokov pred
rodič
commit
0e5071b5fb
2 zmenil súbory, kde vykonal 10 pridanie a 10 odobranie
  1. 1 1
      lobject.h
  2. 9 9
      ltable.c

+ 1 - 1
lobject.h

@@ -68,7 +68,7 @@ typedef struct TValue {
 
 
 #define val_(o)		((o)->value_)
-#define valraw(o)	(&val_(o))
+#define valraw(o)	(val_(o))
 
 
 /* raw type tag of a TValue */

+ 9 - 9
ltable.c

@@ -150,22 +150,22 @@ static int l_hashfloat (lua_Number n) {
 ** and value in 'vkl') so that we can call it on keys inserted into
 ** nodes.
 */
-static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
+static Node *mainposition (const Table *t, int ktt, const Value kvl) {
   switch (withvariant(ktt)) {
     case LUA_VNUMINT: {
-      lua_Integer key = ivalueraw(*kvl);
+      lua_Integer key = ivalueraw(kvl);
       return hashint(t, key);
     }
     case LUA_VNUMFLT: {
-      lua_Number n = fltvalueraw(*kvl);
+      lua_Number n = fltvalueraw(kvl);
       return hashmod(t, l_hashfloat(n));
     }
     case LUA_VSHRSTR: {
-      TString *ts = tsvalueraw(*kvl);
+      TString *ts = tsvalueraw(kvl);
       return hashstr(t, ts);
     }
     case LUA_VLNGSTR: {
-      TString *ts = tsvalueraw(*kvl);
+      TString *ts = tsvalueraw(kvl);
       return hashpow2(t, luaS_hashlongstr(ts));
     }
     case LUA_VFALSE:
@@ -173,15 +173,15 @@ static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
     case LUA_VTRUE:
       return hashboolean(t, 1);
     case LUA_VLIGHTUSERDATA: {
-      void *p = pvalueraw(*kvl);
+      void *p = pvalueraw(kvl);
       return hashpointer(t, p);
     }
     case LUA_VLCF: {
-      lua_CFunction f = fvalueraw(*kvl);
+      lua_CFunction f = fvalueraw(kvl);
       return hashpointer(t, f);
     }
     default: {
-      GCObject *o = gcvalueraw(*kvl);
+      GCObject *o = gcvalueraw(kvl);
       return hashpointer(t, o);
     }
   }
@@ -691,7 +691,7 @@ void luaH_newkey (lua_State *L, Table *t, const TValue *key, TValue *value) {
       return;
     }
     lua_assert(!isdummy(t));
-    othern = mainposition(t, keytt(mp), &keyval(mp));
+    othern = mainposition(t, keytt(mp), keyval(mp));
     if (othern != mp) {  /* is colliding node out of its main position? */
       /* yes; move colliding node into free position */
       while (othern + gnext(othern) != mp)  /* find previous */