** 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). */
| 595 | ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). |
| 596 | */ |
| 597 | int luaH_getn (Table *t) { |
| 598 | unsigned int j = t->sizearray; |
| 599 | if (j > 0 && ttisnil(&t->array[j - 1])) { |
| 600 | /* there is a boundary in the array part: (binary) search for it */ |
| 601 | unsigned int i = 0; |
| 602 | while (j - i > 1) { |
| 603 | unsigned int m = (i+j)/2; |
| 604 | if (ttisnil(&t->array[m - 1])) j = m; |
| 605 | else i = m; |
| 606 | } |
| 607 | return i; |
| 608 | } |
| 609 | /* else must find a boundary in hash part */ |
| 610 | else if (t->node == dummynode) /* hash part is empty? */ |
| 611 | return j; /* that is easy... */ |
| 612 | else return unbound_search(t, j); |
| 613 | } |
| 614 | |
| 615 | |
| 616 |
no test coverage detected