** 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). */
| 561 | ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). |
| 562 | */ |
| 563 | int luaH_getn (Table *t) { |
| 564 | unsigned int j = t->sizearray; |
| 565 | if (j > 0 && ttisnil(&t->array[j - 1])) { |
| 566 | /* there is a boundary in the array part: (binary) search for it */ |
| 567 | unsigned int i = 0; |
| 568 | while (j - i > 1) { |
| 569 | unsigned int m = (i+j)/2; |
| 570 | if (ttisnil(&t->array[m - 1])) j = m; |
| 571 | else i = m; |
| 572 | } |
| 573 | return i; |
| 574 | } |
| 575 | /* else must find a boundary in hash part */ |
| 576 | else if (isdummy(t->node)) /* hash part is empty? */ |
| 577 | return j; /* that is easy... */ |
| 578 | else return unbound_search(t, j); |
| 579 | } |
| 580 | |
| 581 | |
| 582 |
no test coverage detected