diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-08-31 14:57:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-08-31 14:57:33 -0300 |
commit | 1dd8c9b6b6db5500b68a11e097c67e7a39c4f53d (patch) | |
tree | 01a1bc232ff0e31c7fa57eafa1674aa155d23b4c /ltable.c | |
parent | 7d309480dd783112aad8c4761921c4d45ec70327 (diff) | |
download | lua-1dd8c9b6b6db5500b68a11e097c67e7a39c4f53d.tar.gz lua-1dd8c9b6b6db5500b68a11e097c67e7a39c4f53d.tar.bz2 lua-1dd8c9b6b6db5500b68a11e097c67e7a39c4f53d.zip |
detail
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 27 |
1 files changed, 10 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 2.3 2004/04/30 20:13:38 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.4 2004/08/10 19:17:23 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 | */ |
@@ -394,21 +394,6 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) { | |||
394 | 394 | ||
395 | 395 | ||
396 | /* | 396 | /* |
397 | ** generic search function | ||
398 | */ | ||
399 | static const TValue *luaH_getany (Table *t, const TValue *key) { | ||
400 | if (!ttisnil(key)) { | ||
401 | Node *n = luaH_mainposition(t, key); | ||
402 | do { /* check whether `key' is somewhere in the chain */ | ||
403 | if (luaO_rawequalObj(gkey(n), key)) return gval(n); /* that's it */ | ||
404 | else n = n->next; | ||
405 | } while (n); | ||
406 | } | ||
407 | return &luaO_nilobject; | ||
408 | } | ||
409 | |||
410 | |||
411 | /* | ||
412 | ** search function for integers | 397 | ** search function for integers |
413 | */ | 398 | */ |
414 | const TValue *luaH_getnum (Table *t, int key) { | 399 | const TValue *luaH_getnum (Table *t, int key) { |
@@ -446,6 +431,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { | |||
446 | */ | 431 | */ |
447 | const TValue *luaH_get (Table *t, const TValue *key) { | 432 | const TValue *luaH_get (Table *t, const TValue *key) { |
448 | switch (ttype(key)) { | 433 | switch (ttype(key)) { |
434 | case LUA_TNIL: return &luaO_nilobject; | ||
449 | case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); | 435 | case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); |
450 | case LUA_TNUMBER: { | 436 | case LUA_TNUMBER: { |
451 | int k; | 437 | int k; |
@@ -454,7 +440,14 @@ const TValue *luaH_get (Table *t, const TValue *key) { | |||
454 | return luaH_getnum(t, k); /* use specialized version */ | 440 | return luaH_getnum(t, k); /* use specialized version */ |
455 | /* else go through */ | 441 | /* else go through */ |
456 | } | 442 | } |
457 | default: return luaH_getany(t, key); | 443 | default: { |
444 | Node *n = luaH_mainposition(t, key); | ||
445 | do { /* check whether `key' is somewhere in the chain */ | ||
446 | if (luaO_rawequalObj(gkey(n), key)) return gval(n); /* that's it */ | ||
447 | else n = n->next; | ||
448 | } while (n); | ||
449 | return &luaO_nilobject; | ||
450 | } | ||
458 | } | 451 | } |
459 | } | 452 | } |
460 | 453 | ||