** 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). */
| 639 | ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). |
| 640 | */ |
| 641 | int luaH_getn (Table *t) { |
| 642 | unsigned int j = t->sizearray; |
| 643 | if (j > 0 && ttisnil(&t->array[j - 1])) { |
| 644 | /* there is a boundary in the array part: (binary) search for it */ |
| 645 | unsigned int i = 0; |
| 646 | while (j - i > 1) { |
| 647 | unsigned int m = (i+j)/2; |
| 648 | if (ttisnil(&t->array[m - 1])) j = m; |
| 649 | else i = m; |
| 650 | } |
| 651 | return i; |
| 652 | } |
| 653 | /* else must find a boundary in hash part */ |
| 654 | else if (isdummy(t)) /* hash part is empty? */ |
| 655 | return j; /* that is easy... */ |
| 656 | else return unbound_search(t, j); |
| 657 | } |
| 658 | |
| 659 | |
| 660 |
no test coverage detected