MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / luaH_getint

Function luaH_getint

xrepo/packages/l/lua/port/lua/src/ltable.c:728–750  ·  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 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). */

Source from the content-addressed store, hash-verified

726** changing the real size of the array).
727*/
728const TValue *luaH_getint (Table *t, lua_Integer key) {
729 if (l_castS2U(key) - 1u < t->alimit) /* 'key' in [1, t->alimit]? */
730 return &t->array[key - 1];
731 else if (!limitequalsasize(t) && /* key still may be in the array part? */
732 (l_castS2U(key) == t->alimit + 1 ||
733 l_castS2U(key) - 1u < luaH_realasize(t))) {
734 t->alimit = cast_uint(key); /* probably '#t' is here now */
735 return &t->array[key - 1];
736 }
737 else {
738 Node *n = hashint(t, key);
739 for (;;) { /* check whether 'key' is somewhere in the chain */
740 if (keyisinteger(n) && keyival(n) == key)
741 return gval(n); /* that's it */
742 else {
743 int nx = gnext(n);
744 if (nx == 0) break;
745 n += nx;
746 }
747 }
748 return &absentkey;
749 }
750}
751
752
753/*

Callers 5

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

Calls 2

luaH_realasizeFunction · 0.85
hashintFunction · 0.85

Tested by

no test coverage detected