diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-11-25 11:07:17 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-11-25 11:07:17 -0300 |
| commit | ad3942adba574c9d008c99ce2785a5af19d146bf (patch) | |
| tree | c54927eb3d70446f56258e573dafd225bd17d418 | |
| parent | 48835c76c8df62fab4827a9835b351718d20df4b (diff) | |
| download | lua-ad3942adba574c9d008c99ce2785a5af19d146bf.tar.gz lua-ad3942adba574c9d008c99ce2785a5af19d146bf.tar.bz2 lua-ad3942adba574c9d008c99ce2785a5af19d146bf.zip | |
Main 'mainposition' replaced by 'mainpositionTV'
Handle values in table keys as the special cases they are, and not
the other way around.
| -rw-r--r-- | ltable.c | 35 |
1 files changed, 16 insertions, 19 deletions
| @@ -146,26 +146,24 @@ static int l_hashfloat (lua_Number n) { | |||
| 146 | 146 | ||
| 147 | /* | 147 | /* |
| 148 | ** returns the 'main' position of an element in a table (that is, | 148 | ** returns the 'main' position of an element in a table (that is, |
| 149 | ** the index of its hash value). The key comes broken (tag in 'ktt' | 149 | ** the index of its hash value). |
| 150 | ** and value in 'vkl') so that we can call it on keys inserted into | ||
| 151 | ** nodes. | ||
| 152 | */ | 150 | */ |
| 153 | static Node *mainposition (const Table *t, int ktt, const Value kvl) { | 151 | static Node *mainpositionTV (const Table *t, const TValue *key) { |
| 154 | switch (withvariant(ktt)) { | 152 | switch (ttypetag(key)) { |
| 155 | case LUA_VNUMINT: { | 153 | case LUA_VNUMINT: { |
| 156 | lua_Integer key = ivalueraw(kvl); | 154 | lua_Integer i = ivalue(key); |
| 157 | return hashint(t, key); | 155 | return hashint(t, i); |
| 158 | } | 156 | } |
| 159 | case LUA_VNUMFLT: { | 157 | case LUA_VNUMFLT: { |
| 160 | lua_Number n = fltvalueraw(kvl); | 158 | lua_Number n = fltvalue(key); |
| 161 | return hashmod(t, l_hashfloat(n)); | 159 | return hashmod(t, l_hashfloat(n)); |
| 162 | } | 160 | } |
| 163 | case LUA_VSHRSTR: { | 161 | case LUA_VSHRSTR: { |
| 164 | TString *ts = tsvalueraw(kvl); | 162 | TString *ts = tsvalue(key); |
| 165 | return hashstr(t, ts); | 163 | return hashstr(t, ts); |
| 166 | } | 164 | } |
| 167 | case LUA_VLNGSTR: { | 165 | case LUA_VLNGSTR: { |
| 168 | TString *ts = tsvalueraw(kvl); | 166 | TString *ts = tsvalue(key); |
| 169 | return hashpow2(t, luaS_hashlongstr(ts)); | 167 | return hashpow2(t, luaS_hashlongstr(ts)); |
| 170 | } | 168 | } |
| 171 | case LUA_VFALSE: | 169 | case LUA_VFALSE: |
| @@ -173,26 +171,25 @@ static Node *mainposition (const Table *t, int ktt, const Value kvl) { | |||
| 173 | case LUA_VTRUE: | 171 | case LUA_VTRUE: |
| 174 | return hashboolean(t, 1); | 172 | return hashboolean(t, 1); |
| 175 | case LUA_VLIGHTUSERDATA: { | 173 | case LUA_VLIGHTUSERDATA: { |
| 176 | void *p = pvalueraw(kvl); | 174 | void *p = pvalue(key); |
| 177 | return hashpointer(t, p); | 175 | return hashpointer(t, p); |
| 178 | } | 176 | } |
| 179 | case LUA_VLCF: { | 177 | case LUA_VLCF: { |
| 180 | lua_CFunction f = fvalueraw(kvl); | 178 | lua_CFunction f = fvalue(key); |
| 181 | return hashpointer(t, f); | 179 | return hashpointer(t, f); |
| 182 | } | 180 | } |
| 183 | default: { | 181 | default: { |
| 184 | GCObject *o = gcvalueraw(kvl); | 182 | GCObject *o = gcvalue(key); |
| 185 | return hashpointer(t, o); | 183 | return hashpointer(t, o); |
| 186 | } | 184 | } |
| 187 | } | 185 | } |
| 188 | } | 186 | } |
| 189 | 187 | ||
| 190 | 188 | ||
| 191 | /* | 189 | l_sinline Node *mainpositionfromnode (const Table *t, Node *nd) { |
| 192 | ** Returns the main position of an element given as a 'TValue' | 190 | TValue key; |
| 193 | */ | 191 | getnodekey(cast(lua_State *, NULL), &key, nd); |
| 194 | static Node *mainpositionTV (const Table *t, const TValue *key) { | 192 | return mainpositionTV(t, &key); |
| 195 | return mainposition(t, rawtt(key), valraw(key)); | ||
| 196 | } | 193 | } |
| 197 | 194 | ||
| 198 | 195 | ||
| @@ -691,7 +688,7 @@ void luaH_newkey (lua_State *L, Table *t, const TValue *key, TValue *value) { | |||
| 691 | return; | 688 | return; |
| 692 | } | 689 | } |
| 693 | lua_assert(!isdummy(t)); | 690 | lua_assert(!isdummy(t)); |
| 694 | othern = mainposition(t, keytt(mp), keyval(mp)); | 691 | othern = mainpositionfromnode(t, mp); |
| 695 | if (othern != mp) { /* is colliding node out of its main position? */ | 692 | if (othern != mp) { /* is colliding node out of its main position? */ |
| 696 | /* yes; move colliding node into free position */ | 693 | /* yes; move colliding node into free position */ |
| 697 | while (othern + gnext(othern) != mp) /* find previous */ | 694 | while (othern + gnext(othern) != mp) /* find previous */ |
