Clearer distinction between types and tags
LUA_T* represents only types; tags (types + Variants) are represented by LUA_V* constants.
This commit is contained in:
46
ltable.c
46
ltable.c
@@ -88,8 +88,8 @@
|
||||
#define dummynode (&dummynode_)
|
||||
|
||||
static const Node dummynode_ = {
|
||||
{{NULL}, LUA_TEMPTY, /* value's value and type */
|
||||
LUA_TNIL, 0, {NULL}} /* key type, next, and key value */
|
||||
{{NULL}, LUA_VEMPTY, /* value's value and type */
|
||||
LUA_VNIL, 0, {NULL}} /* key type, next, and key value */
|
||||
};
|
||||
|
||||
|
||||
@@ -135,21 +135,21 @@ static int l_hashfloat (lua_Number n) {
|
||||
*/
|
||||
static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
|
||||
switch (withvariant(ktt)) {
|
||||
case LUA_TNUMINT:
|
||||
case LUA_VNUMINT:
|
||||
return hashint(t, ivalueraw(*kvl));
|
||||
case LUA_TNUMFLT:
|
||||
case LUA_VNUMFLT:
|
||||
return hashmod(t, l_hashfloat(fltvalueraw(*kvl)));
|
||||
case LUA_TSHRSTR:
|
||||
case LUA_VSHRSTR:
|
||||
return hashstr(t, tsvalueraw(*kvl));
|
||||
case LUA_TLNGSTR:
|
||||
case LUA_VLNGSTR:
|
||||
return hashpow2(t, luaS_hashlongstr(tsvalueraw(*kvl)));
|
||||
case LUA_TFALSE:
|
||||
case LUA_VFALSE:
|
||||
return hashboolean(t, 0);
|
||||
case LUA_TTRUE:
|
||||
case LUA_VTRUE:
|
||||
return hashboolean(t, 1);
|
||||
case LUA_TLIGHTUSERDATA:
|
||||
case LUA_VLIGHTUSERDATA:
|
||||
return hashpointer(t, pvalueraw(*kvl));
|
||||
case LUA_TLCF:
|
||||
case LUA_VLCF:
|
||||
return hashpointer(t, fvalueraw(*kvl));
|
||||
default:
|
||||
return hashpointer(t, gcvalueraw(*kvl));
|
||||
@@ -177,17 +177,17 @@ static int equalkey (const TValue *k1, const Node *n2) {
|
||||
if (rawtt(k1) != keytt(n2)) /* not the same variants? */
|
||||
return 0; /* cannot be same key */
|
||||
switch (ttypetag(k1)) {
|
||||
case LUA_TNIL: case LUA_TFALSE: case LUA_TTRUE:
|
||||
case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE:
|
||||
return 1;
|
||||
case LUA_TNUMINT:
|
||||
case LUA_VNUMINT:
|
||||
return (ivalue(k1) == keyival(n2));
|
||||
case LUA_TNUMFLT:
|
||||
case LUA_VNUMFLT:
|
||||
return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2)));
|
||||
case LUA_TLIGHTUSERDATA:
|
||||
case LUA_VLIGHTUSERDATA:
|
||||
return pvalue(k1) == pvalueraw(keyval(n2));
|
||||
case LUA_TLCF:
|
||||
case LUA_VLCF:
|
||||
return fvalue(k1) == fvalueraw(keyval(n2));
|
||||
case LUA_TLNGSTR:
|
||||
case LUA_VLNGSTR:
|
||||
return luaS_eqlngstr(tsvalue(k1), keystrval(n2));
|
||||
default:
|
||||
return gcvalue(k1) == gcvalueraw(keyval(n2));
|
||||
@@ -580,7 +580,7 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) {
|
||||
|
||||
|
||||
Table *luaH_new (lua_State *L) {
|
||||
GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));
|
||||
GCObject *o = luaC_newobj(L, LUA_VTABLE, sizeof(Table));
|
||||
Table *t = gco2t(o);
|
||||
t->metatable = NULL;
|
||||
t->flags = cast_byte(~0);
|
||||
@@ -710,7 +710,7 @@ const TValue *luaH_getint (Table *t, lua_Integer key) {
|
||||
*/
|
||||
const TValue *luaH_getshortstr (Table *t, TString *key) {
|
||||
Node *n = hashstr(t, key);
|
||||
lua_assert(key->tt == LUA_TSHRSTR);
|
||||
lua_assert(key->tt == LUA_VSHRSTR);
|
||||
for (;;) { /* check whether 'key' is somewhere in the chain */
|
||||
if (keyisshrstr(n) && eqshrstr(keystrval(n), key))
|
||||
return gval(n); /* that's it */
|
||||
@@ -725,7 +725,7 @@ const TValue *luaH_getshortstr (Table *t, TString *key) {
|
||||
|
||||
|
||||
const TValue *luaH_getstr (Table *t, TString *key) {
|
||||
if (key->tt == LUA_TSHRSTR)
|
||||
if (key->tt == LUA_VSHRSTR)
|
||||
return luaH_getshortstr(t, key);
|
||||
else { /* for long strings, use generic case */
|
||||
TValue ko;
|
||||
@@ -740,10 +740,10 @@ const TValue *luaH_getstr (Table *t, TString *key) {
|
||||
*/
|
||||
const TValue *luaH_get (Table *t, const TValue *key) {
|
||||
switch (ttypetag(key)) {
|
||||
case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));
|
||||
case LUA_TNUMINT: return luaH_getint(t, ivalue(key));
|
||||
case LUA_TNIL: return &absentkey;
|
||||
case LUA_TNUMFLT: {
|
||||
case LUA_VSHRSTR: return luaH_getshortstr(t, tsvalue(key));
|
||||
case LUA_VNUMINT: return luaH_getint(t, ivalue(key));
|
||||
case LUA_VNIL: return &absentkey;
|
||||
case LUA_VNUMFLT: {
|
||||
lua_Integer k;
|
||||
if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */
|
||||
return luaH_getint(t, k); /* use specialized version */
|
||||
|
||||
Reference in New Issue
Block a user