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