** 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). */
| 773 | ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). |
| 774 | */ |
| 775 | int luaH_getn(Table *t) { |
| 776 | unsigned int j = t->sizearray; |
| 777 | if (j > 0 && ttisnil(&t->array[j - 1])) { |
| 778 | /* there is a boundary in the array part: (binary) search for it */ |
| 779 | unsigned int i = 0; |
| 780 | while (j - i > 1) { |
| 781 | unsigned int m = (i + j) / 2; |
| 782 | if (ttisnil(&t->array[m - 1])) j = m; |
| 783 | else i = m; |
| 784 | } |
| 785 | return i; |
| 786 | } |
| 787 | /* else must find a boundary in hash part */ |
| 788 | else if (isdummy(t->node)) /* hash part is empty? */ |
| 789 | return j; /* that is easy... */ |
| 790 | else return unbound_search(t, j); |
| 791 | } |
| 792 | |
| 793 | |
| 794 |
no test coverage detected