eris: deterministic table length operator

This commit is contained in:
2021-07-05 12:12:32 -04:00
parent be529afc55
commit 596d829ea6

View File

@@ -558,21 +558,23 @@ static int unbound_search (Table *t, unsigned int j) {
** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
*/ */
int luaH_getn (Table *t) { int luaH_getn (Table *t) {
unsigned int j = t->sizearray; return unbound_search(t, 0);
if (j > 0 && ttisnil(&t->array[j - 1])) {
/* there is a boundary in the array part: (binary) search for it */ // unsigned int j = t->sizearray;
unsigned int i = 0; // if (j > 0 && ttisnil(&t->array[j - 1])) {
while (j - i > 1) { // /* there is a boundary in the array part: (binary) search for it */
unsigned int m = (i+j)/2; // unsigned int i = 0;
if (ttisnil(&t->array[m - 1])) j = m; // while (j - i > 1) {
else i = m; // unsigned int m = (i+j)/2;
} // if (ttisnil(&t->array[m - 1])) j = m;
return i; // else i = m;
} // }
/* else must find a boundary in hash part */ // return i;
else if (isdummy(t->node)) /* hash part is empty? */ // }
return j; /* that is easy... */ // /* else must find a boundary in hash part */
else return unbound_search(t, j); // else if (isdummy(t->node)) /* hash part is empty? */
// return j; /* that is easy... */
// else return unbound_search(t, j);
} }