** search function for integers */
| 466 | ** search function for integers |
| 467 | */ |
| 468 | static const TValue *luaH_getnum_int (Table *t, int key, |
| 469 | TValue **foundkey) { |
| 470 | /* (1 <= key && key <= t->sizearray) */ |
| 471 | if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) { |
| 472 | if (foundkey) |
| 473 | *foundkey = NULL; |
| 474 | return &t->array[key-1]; |
| 475 | } |
| 476 | |
| 477 | int found = 0; |
| 478 | lua_Number nk = cast_num(key); |
| 479 | Node *n = hashnum(t, nk); |
| 480 | do { /* check whether `key' is somewhere in the chain */ |
| 481 | if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) { |
| 482 | found = 1; |
| 483 | } else if (ttisuserdata(gkey(n))) { |
| 484 | double d; |
| 485 | void *udata = rawuvalue(gkey(n)) + 1; |
| 486 | if (luabb_hashinfo(udata, &d, NULL, NULL) == Numeric |
| 487 | && luai_numeq(d, nk)) { |
| 488 | found = 1; |
| 489 | } |
| 490 | } |
| 491 | if (found) { |
| 492 | if (foundkey) |
| 493 | *foundkey = key2tval(n); |
| 494 | return gval(n); /* that's it */ |
| 495 | } |
| 496 | n = gnext(n); |
| 497 | } while (n); |
| 498 | return luaO_nilobject; |
| 499 | } |
| 500 | |
| 501 | |
| 502 | const TValue *luaH_getnum (Table *t, int key) { |
no test coverage detected