diff options
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 48 |
1 files changed, 30 insertions, 18 deletions
@@ -904,14 +904,23 @@ static int hashkeyisempty (Table *t, lua_Integer key) { | |||
904 | } | 904 | } |
905 | 905 | ||
906 | 906 | ||
907 | TValue luaH_getint (Table *t, lua_Integer key) { | 907 | static int finishnodeget (const TValue *val, TValue *res) { |
908 | if (!ttisnil(val)) { | ||
909 | setobj(((lua_State*)NULL), res, val); | ||
910 | } | ||
911 | return ttypetag(val); | ||
912 | } | ||
913 | |||
914 | |||
915 | int luaH_getint (Table *t, lua_Integer key, TValue *res) { | ||
908 | if (keyinarray(t, key)) { | 916 | if (keyinarray(t, key)) { |
909 | TValue res; | 917 | int tag = *getArrTag(t, key - 1); |
910 | arr2objV(t, key, res); | 918 | if (!tagisempty(tag)) |
911 | return res; | 919 | farr2val(t, key, tag, res); |
920 | return tag; | ||
912 | } | 921 | } |
913 | else | 922 | else |
914 | return *getintfromhash(t, key); | 923 | return finishnodeget(getintfromhash(t, key), res); |
915 | } | 924 | } |
916 | 925 | ||
917 | 926 | ||
@@ -934,8 +943,8 @@ const TValue *luaH_Hgetshortstr (Table *t, TString *key) { | |||
934 | } | 943 | } |
935 | 944 | ||
936 | 945 | ||
937 | TValue luaH_getshortstr (Table *t, TString *key) { | 946 | int luaH_getshortstr (Table *t, TString *key, TValue *res) { |
938 | return *luaH_Hgetshortstr(t, key); | 947 | return finishnodeget(luaH_Hgetshortstr(t, key), res); |
939 | } | 948 | } |
940 | 949 | ||
941 | 950 | ||
@@ -950,8 +959,8 @@ static const TValue *Hgetstr (Table *t, TString *key) { | |||
950 | } | 959 | } |
951 | 960 | ||
952 | 961 | ||
953 | TValue luaH_getstr (Table *t, TString *key) { | 962 | int luaH_getstr (Table *t, TString *key, TValue *res) { |
954 | return *Hgetstr(t, key); | 963 | return finishnodeget(Hgetstr(t, key), res); |
955 | } | 964 | } |
956 | 965 | ||
957 | 966 | ||
@@ -967,31 +976,34 @@ TString *luaH_getstrkey (Table *t, TString *key) { | |||
967 | /* | 976 | /* |
968 | ** main search function | 977 | ** main search function |
969 | */ | 978 | */ |
970 | TValue luaH_get (Table *t, const TValue *key) { | 979 | int luaH_get (Table *t, const TValue *key, TValue *res) { |
980 | const TValue *slot; | ||
971 | switch (ttypetag(key)) { | 981 | switch (ttypetag(key)) { |
972 | case LUA_VSHRSTR: | 982 | case LUA_VSHRSTR: |
973 | return *luaH_Hgetshortstr(t, tsvalue(key)); | 983 | slot = luaH_Hgetshortstr(t, tsvalue(key)); |
974 | break; | 984 | break; |
975 | case LUA_VNUMINT: | 985 | case LUA_VNUMINT: |
976 | return luaH_getint(t, ivalue(key)); | 986 | return luaH_getint(t, ivalue(key), res); |
977 | case LUA_VNIL: | 987 | case LUA_VNIL: |
978 | return absentkey; | 988 | slot = &absentkey; |
979 | break; | 989 | break; |
980 | case LUA_VNUMFLT: { | 990 | case LUA_VNUMFLT: { |
981 | lua_Integer k; | 991 | lua_Integer k; |
982 | if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */ | 992 | if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */ |
983 | return luaH_getint(t, k); /* use specialized version */ | 993 | return luaH_getint(t, k, res); /* use specialized version */ |
984 | /* else... */ | 994 | /* else... */ |
985 | } /* FALLTHROUGH */ | 995 | } /* FALLTHROUGH */ |
986 | default: | 996 | default: |
987 | return *getgeneric(t, key, 0); | 997 | slot = getgeneric(t, key, 0); |
998 | break; | ||
988 | } | 999 | } |
1000 | return finishnodeget(slot, res); | ||
989 | } | 1001 | } |
990 | 1002 | ||
991 | 1003 | ||
992 | static int finishnodeset (Table *t, const TValue *slot, TValue *val) { | 1004 | static int finishnodeset (Table *t, const TValue *slot, TValue *val) { |
993 | if (!ttisnil(slot)) { | 1005 | if (!ttisnil(slot)) { |
994 | setobj(cast(lua_State*, NULL), cast(TValue*, slot), val); | 1006 | setobj(((lua_State*)NULL), cast(TValue*, slot), val); |
995 | return HOK; /* success */ | 1007 | return HOK; /* success */ |
996 | } | 1008 | } |
997 | else if (isabstkey(slot)) | 1009 | else if (isabstkey(slot)) |
@@ -1005,7 +1017,7 @@ static int rawfinishnodeset (const TValue *slot, TValue *val) { | |||
1005 | if (isabstkey(slot)) | 1017 | if (isabstkey(slot)) |
1006 | return 0; /* no slot with that key */ | 1018 | return 0; /* no slot with that key */ |
1007 | else { | 1019 | else { |
1008 | setobj(cast(lua_State*, NULL), cast(TValue*, slot), val); | 1020 | setobj(((lua_State*)NULL), cast(TValue*, slot), val); |
1009 | return 1; /* success */ | 1021 | return 1; /* success */ |
1010 | } | 1022 | } |
1011 | } | 1023 | } |