** Search function for integers. If integer is inside 'alimit', get it ** directly from the array part. Otherwise, if 'alimit' is not equal to ** the real size of the array, key still can be in the array part. In ** this case, try to avoid a call to 'luaH_realasize' when key is just ** one more than the limit (so that it can be incremented without ** changing the real size of the array). */
| 717 | ** changing the real size of the array). |
| 718 | */ |
| 719 | const TValue *luaH_getint (Table *t, lua_Integer key) { |
| 720 | if (l_castS2U(key) - 1u < t->alimit) /* 'key' in [1, t->alimit]? */ |
| 721 | return &t->array[key - 1]; |
| 722 | else if (!limitequalsasize(t) && /* key still may be in the array part? */ |
| 723 | (l_castS2U(key) == t->alimit + 1 || |
| 724 | l_castS2U(key) - 1u < luaH_realasize(t))) { |
| 725 | t->alimit = cast_uint(key); /* probably '#t' is here now */ |
| 726 | return &t->array[key - 1]; |
| 727 | } |
| 728 | else { |
| 729 | Node *n = hashint(t, key); |
| 730 | for (;;) { /* check whether 'key' is somewhere in the chain */ |
| 731 | if (keyisinteger(n) && keyival(n) == key) |
| 732 | return gval(n); /* that's it */ |
| 733 | else { |
| 734 | int nx = gnext(n); |
| 735 | if (nx == 0) break; |
| 736 | n += nx; |
| 737 | } |
| 738 | } |
| 739 | return &absentkey; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | |
| 744 | /* |
no test coverage detected