MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaH_getn

Function luaH_getn

depends/lua/src/ltable.c:660–676  ·  view source on GitHub ↗

** Try to find a boundary in table 't'. A 'boundary' is an integer index ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). */

Source from the content-addressed store, hash-verified

658** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
659*/
660lua_Unsigned luaH_getn (Table *t) {
661 unsigned int j = t->sizearray;
662 if (j > 0 && ttisnil(&t->array[j - 1])) {
663 /* there is a boundary in the array part: (binary) search for it */
664 unsigned int i = 0;
665 while (j - i > 1) {
666 unsigned int m = (i+j)/2;
667 if (ttisnil(&t->array[m - 1])) j = m;
668 else i = m;
669 }
670 return i;
671 }
672 /* else must find a boundary in hash part */
673 else if (isdummy(t)) /* hash part is empty? */
674 return j; /* that is easy... */
675 else return unbound_search(t, j);
676}
677
678
679

Callers 2

luaV_objlenFunction · 0.85
lua_rawlenFunction · 0.85

Calls 1

unbound_searchFunction · 0.85

Tested by

no test coverage detected