diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-03-18 15:56:32 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-03-18 15:56:32 -0300 |
| commit | ce6f5502c99ce9a367e25b678e375db6f8164d73 (patch) | |
| tree | 47f36dc2f6da96dfda325d7b587f3a20599e9317 /ltable.c | |
| parent | ba710603811c68fe3a69b3bb98e9038d37489a79 (diff) | |
| download | lua-ce6f5502c99ce9a367e25b678e375db6f8164d73.tar.gz lua-ce6f5502c99ce9a367e25b678e375db6f8164d73.tar.bz2 lua-ce6f5502c99ce9a367e25b678e375db6f8164d73.zip | |
'luaH_get' functions return 'TValue'
Instead of receiving a parameter telling them where to put the result
of the query, these functions return the TValue directly. (That is,
they return a structure.)
Diffstat (limited to 'ltable.c')
| -rw-r--r-- | ltable.c | 53 |
1 files changed, 18 insertions, 35 deletions
| @@ -904,28 +904,14 @@ static int hashkeyisempty (Table *t, lua_Integer key) { | |||
| 904 | } | 904 | } |
| 905 | 905 | ||
| 906 | 906 | ||
| 907 | static int finishnodeget (const TValue *val, TValue *res) { | 907 | TValue luaH_getint (Table *t, lua_Integer key) { |
| 908 | if (!ttisnil(val)) { | ||
| 909 | setobj(((lua_State*)NULL), res, val); | ||
| 910 | return HOK; /* success */ | ||
| 911 | } | ||
| 912 | else | ||
| 913 | return HNOTFOUND; /* could not get value */ | ||
| 914 | } | ||
| 915 | |||
| 916 | |||
| 917 | int luaH_getint (Table *t, lua_Integer key, TValue *res) { | ||
| 918 | if (keyinarray(t, key)) { | 908 | if (keyinarray(t, key)) { |
| 919 | int tag = *getArrTag(t, key - 1); | 909 | TValue res; |
| 920 | if (!tagisempty(tag)) { | 910 | arr2objV(t, key, res); |
| 921 | farr2val(t, key, tag, res); | 911 | return res; |
| 922 | return HOK; /* success */ | ||
| 923 | } | ||
| 924 | else | ||
| 925 | return ~cast_int(key); /* empty slot in the array part */ | ||
| 926 | } | 912 | } |
| 927 | else | 913 | else |
| 928 | return finishnodeget(getintfromhash(t, key), res); | 914 | return *getintfromhash(t, key); |
| 929 | } | 915 | } |
| 930 | 916 | ||
| 931 | 917 | ||
| @@ -948,8 +934,8 @@ const TValue *luaH_Hgetshortstr (Table *t, TString *key) { | |||
| 948 | } | 934 | } |
| 949 | 935 | ||
| 950 | 936 | ||
| 951 | int luaH_getshortstr (Table *t, TString *key, TValue *res) { | 937 | TValue luaH_getshortstr (Table *t, TString *key) { |
| 952 | return finishnodeget(luaH_Hgetshortstr(t, key), res); | 938 | return *luaH_Hgetshortstr(t, key); |
| 953 | } | 939 | } |
| 954 | 940 | ||
| 955 | 941 | ||
| @@ -964,8 +950,8 @@ static const TValue *Hgetstr (Table *t, TString *key) { | |||
| 964 | } | 950 | } |
| 965 | 951 | ||
| 966 | 952 | ||
| 967 | int luaH_getstr (Table *t, TString *key, TValue *res) { | 953 | TValue luaH_getstr (Table *t, TString *key) { |
| 968 | return finishnodeget(Hgetstr(t, key), res); | 954 | return *Hgetstr(t, key); |
| 969 | } | 955 | } |
| 970 | 956 | ||
| 971 | 957 | ||
| @@ -981,34 +967,31 @@ TString *luaH_getstrkey (Table *t, TString *key) { | |||
| 981 | /* | 967 | /* |
| 982 | ** main search function | 968 | ** main search function |
| 983 | */ | 969 | */ |
| 984 | int luaH_get (Table *t, const TValue *key, TValue *res) { | 970 | TValue luaH_get (Table *t, const TValue *key) { |
| 985 | const TValue *slot; | ||
| 986 | switch (ttypetag(key)) { | 971 | switch (ttypetag(key)) { |
| 987 | case LUA_VSHRSTR: | 972 | case LUA_VSHRSTR: |
| 988 | slot = luaH_Hgetshortstr(t, tsvalue(key)); | 973 | return *luaH_Hgetshortstr(t, tsvalue(key)); |
| 989 | break; | 974 | break; |
| 990 | case LUA_VNUMINT: | 975 | case LUA_VNUMINT: |
| 991 | return luaH_getint(t, ivalue(key), res); | 976 | return luaH_getint(t, ivalue(key)); |
| 992 | case LUA_VNIL: | 977 | case LUA_VNIL: |
| 993 | slot = &absentkey; | 978 | return absentkey; |
| 994 | break; | 979 | break; |
| 995 | case LUA_VNUMFLT: { | 980 | case LUA_VNUMFLT: { |
| 996 | lua_Integer k; | 981 | lua_Integer k; |
| 997 | if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */ | 982 | if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */ |
| 998 | return luaH_getint(t, k, res); /* use specialized version */ | 983 | return luaH_getint(t, k); /* use specialized version */ |
| 999 | /* else... */ | 984 | /* else... */ |
| 1000 | } /* FALLTHROUGH */ | 985 | } /* FALLTHROUGH */ |
| 1001 | default: | 986 | default: |
| 1002 | slot = getgeneric(t, key, 0); | 987 | return *getgeneric(t, key, 0); |
| 1003 | break; | ||
| 1004 | } | 988 | } |
| 1005 | return finishnodeget(slot, res); | ||
| 1006 | } | 989 | } |
| 1007 | 990 | ||
| 1008 | 991 | ||
| 1009 | static int finishnodeset (Table *t, const TValue *slot, TValue *val) { | 992 | static int finishnodeset (Table *t, const TValue *slot, TValue *val) { |
| 1010 | if (!ttisnil(slot)) { | 993 | if (!ttisnil(slot)) { |
| 1011 | setobj(((lua_State*)NULL), cast(TValue*, slot), val); | 994 | setobj(cast(lua_State*, NULL), cast(TValue*, slot), val); |
| 1012 | return HOK; /* success */ | 995 | return HOK; /* success */ |
| 1013 | } | 996 | } |
| 1014 | else if (isabstkey(slot)) | 997 | else if (isabstkey(slot)) |
| @@ -1022,7 +1005,7 @@ static int rawfinishnodeset (const TValue *slot, TValue *val) { | |||
| 1022 | if (isabstkey(slot)) | 1005 | if (isabstkey(slot)) |
| 1023 | return 0; /* no slot with that key */ | 1006 | return 0; /* no slot with that key */ |
| 1024 | else { | 1007 | else { |
| 1025 | setobj(((lua_State*)NULL), cast(TValue*, slot), val); | 1008 | setobj(cast(lua_State*, NULL), cast(TValue*, slot), val); |
| 1026 | return 1; /* success */ | 1009 | return 1; /* success */ |
| 1027 | } | 1010 | } |
| 1028 | } | 1011 | } |
