MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaH_getint

Function luaH_getint

lib/lua/src/ltable.c:745–767  ·  view source on GitHub ↗

** Search function for integers. If integer is inside 'alimit', get it ** directly from the array part. Otherwise, if 'alimit' is not ** the real size of the array, the key still can be in the array part. ** In this case, do the "Xmilia trick" to check whether 'key-1' is ** smaller than the real size. ** The trick works as follow: let 'p' be an integer such that ** '2^(p+1) >= alimit > 2^p', or

Source from the content-addressed store, hash-verified

743** if cannot be smaller than alimit.
744*/
745const TValue *luaH_getint (Table *t, lua_Integer key) {
746 lua_Unsigned alimit = t->alimit;
747 if (l_castS2U(key) - 1u < alimit) /* 'key' in [1, t->alimit]? */
748 return &t->array[key - 1];
749 else if (!isrealasize(t) && /* key still may be in the array part? */
750 (((l_castS2U(key) - 1u) & ~(alimit - 1u)) < alimit)) {
751 t->alimit = cast_uint(key); /* probably '#t' is here now */
752 return &t->array[key - 1];
753 }
754 else { /* key is not in the array part; check the hash */
755 Node *n = hashint(t, key);
756 for (;;) { /* check whether 'key' is somewhere in the chain */
757 if (keyisinteger(n) && keyival(n) == key)
758 return gval(n); /* that's it */
759 else {
760 int nx = gnext(n);
761 if (nx == 0) break;
762 n += nx;
763 }
764 }
765 return &absentkey;
766 }
767}
768
769
770/*

Callers 5

luaH_getFunction · 0.85
luaH_setintFunction · 0.85
hash_searchFunction · 0.85
luaH_getnFunction · 0.85
lua_rawgetiFunction · 0.85

Calls 1

hashintFunction · 0.85

Tested by

no test coverage detected