** 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). */
| 620 | ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). |
| 621 | */ |
| 622 | int luaH_getn (Table *t) { |
| 623 | unsigned int j = t->sizearray; |
| 624 | if (j > 0 && ttisnil(&t->array[j - 1])) { |
| 625 | /* there is a boundary in the array part: (binary) search for it */ |
| 626 | unsigned int i = 0; |
| 627 | while (j - i > 1) { |
| 628 | unsigned int m = (i+j)/2; |
| 629 | if (ttisnil(&t->array[m - 1])) j = m; |
| 630 | else i = m; |
| 631 | } |
| 632 | return i; |
| 633 | } |
| 634 | /* else must find a boundary in hash part */ |
| 635 | else if (isdummy(t->node)) /* hash part is empty? */ |
| 636 | return j; /* that is easy... */ |
| 637 | else return unbound_search(t, j); |
| 638 | } |
| 639 | |
| 640 | |
| 641 |
no test coverage detected