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