diff options
Diffstat (limited to 'ltable.c')
| -rw-r--r-- | ltable.c | 19 |
1 files changed, 10 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.136 2018/05/29 18:01:50 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.137 2018/05/30 14:25:52 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -93,7 +93,8 @@ static const Node dummynode_ = { | |||
| 93 | }; | 93 | }; |
| 94 | 94 | ||
| 95 | 95 | ||
| 96 | LUAI_DDEF const TValue luaH_emptyobject_ = {EMPTYCONSTANT}; | 96 | static const TValue absentkey = {ABSTKEYCONSTANT}; |
| 97 | |||
| 97 | 98 | ||
| 98 | 99 | ||
| 99 | /* | 100 | /* |
| @@ -203,7 +204,7 @@ static const TValue *getgeneric (Table *t, const TValue *key) { | |||
| 203 | else { | 204 | else { |
| 204 | int nx = gnext(n); | 205 | int nx = gnext(n); |
| 205 | if (nx == 0) | 206 | if (nx == 0) |
| 206 | return luaH_emptyobject; /* not found */ | 207 | return &absentkey; /* not found */ |
| 207 | n += nx; | 208 | n += nx; |
| 208 | } | 209 | } |
| 209 | } | 210 | } |
| @@ -235,7 +236,7 @@ static unsigned int findindex (lua_State *L, Table *t, TValue *key) { | |||
| 235 | return i; /* yes; that's the index */ | 236 | return i; /* yes; that's the index */ |
| 236 | else { | 237 | else { |
| 237 | const TValue *n = getgeneric(t, key); | 238 | const TValue *n = getgeneric(t, key); |
| 238 | if (unlikely(n == luaH_emptyobject)) | 239 | if (unlikely(isabstkey(n))) |
| 239 | luaG_runerror(L, "invalid key to 'next'"); /* key not found */ | 240 | luaG_runerror(L, "invalid key to 'next'"); /* key not found */ |
| 240 | i = cast_int(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ | 241 | i = cast_int(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ |
| 241 | /* hash elements are numbered after array ones */ | 242 | /* hash elements are numbered after array ones */ |
| @@ -629,7 +630,7 @@ const TValue *luaH_getint (Table *t, lua_Integer key) { | |||
| 629 | n += nx; | 630 | n += nx; |
| 630 | } | 631 | } |
| 631 | } | 632 | } |
| 632 | return luaH_emptyobject; | 633 | return &absentkey; |
| 633 | } | 634 | } |
| 634 | } | 635 | } |
| 635 | 636 | ||
| @@ -646,7 +647,7 @@ const TValue *luaH_getshortstr (Table *t, TString *key) { | |||
| 646 | else { | 647 | else { |
| 647 | int nx = gnext(n); | 648 | int nx = gnext(n); |
| 648 | if (nx == 0) | 649 | if (nx == 0) |
| 649 | return luaH_emptyobject; /* not found */ | 650 | return &absentkey; /* not found */ |
| 650 | n += nx; | 651 | n += nx; |
| 651 | } | 652 | } |
| 652 | } | 653 | } |
| @@ -671,7 +672,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { | |||
| 671 | switch (ttypetag(key)) { | 672 | switch (ttypetag(key)) { |
| 672 | case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key)); | 673 | case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key)); |
| 673 | case LUA_TNUMINT: return luaH_getint(t, ivalue(key)); | 674 | case LUA_TNUMINT: return luaH_getint(t, ivalue(key)); |
| 674 | case LUA_TNIL: return luaH_emptyobject; | 675 | case LUA_TNIL: return &absentkey; |
| 675 | case LUA_TNUMFLT: { | 676 | case LUA_TNUMFLT: { |
| 676 | lua_Integer k; | 677 | lua_Integer k; |
| 677 | if (luaV_flttointeger(fltvalue(key), &k, 0)) /* index is an integral? */ | 678 | if (luaV_flttointeger(fltvalue(key), &k, 0)) /* index is an integral? */ |
| @@ -690,7 +691,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { | |||
| 690 | */ | 691 | */ |
| 691 | TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { | 692 | TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { |
| 692 | const TValue *p = luaH_get(t, key); | 693 | const TValue *p = luaH_get(t, key); |
| 693 | if (p != luaH_emptyobject) | 694 | if (!isabstkey(p)) |
| 694 | return cast(TValue *, p); | 695 | return cast(TValue *, p); |
| 695 | else return luaH_newkey(L, t, key); | 696 | else return luaH_newkey(L, t, key); |
| 696 | } | 697 | } |
| @@ -699,7 +700,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { | |||
| 699 | void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) { | 700 | void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) { |
| 700 | const TValue *p = luaH_getint(t, key); | 701 | const TValue *p = luaH_getint(t, key); |
| 701 | TValue *cell; | 702 | TValue *cell; |
| 702 | if (p != luaH_emptyobject) | 703 | if (!isabstkey(p)) |
| 703 | cell = cast(TValue *, p); | 704 | cell = cast(TValue *, p); |
| 704 | else { | 705 | else { |
| 705 | TValue k; | 706 | TValue k; |
