** 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). */
| 659 | ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). |
| 660 | */ |
| 661 | int luaH_getn (Table *t) { |
| 662 | unsigned int j = t->sizearray; |
| 663 | if (j > 0 && ttisnil(&t->array[j - 1])) { |
| 664 | /* there is a boundary in the array part: (binary) search for it */ |
| 665 | unsigned int i = 0; |
| 666 | while (j - i > 1) { |
| 667 | unsigned int m = (i+j)/2; |
| 668 | if (ttisnil(&t->array[m - 1])) j = m; |
| 669 | else i = m; |
| 670 | } |
| 671 | return i; |
| 672 | } |
| 673 | /* else must find a boundary in hash part */ |
| 674 | else if (t->node == dummynode) /* hash part is empty? */ |
| 675 | return j; /* that is easy... */ |
| 676 | else return unbound_search(t, j); |
| 677 | } |
| 678 | |
| 679 | |
| 680 |
no test coverage detected