Fill an interior page with cells from children[*idx..child_count-2]. Updates cell_count, content_offset, ptr_offset, and *idx.
| 652 | // Fill an interior page with cells from children[*idx..child_count-2]. |
| 653 | // Updates cell_count, content_offset, ptr_offset, and *idx. |
| 654 | static void fill_interior_page(uint8_t *page, const PageRef *children, int child_count, |
| 655 | bool is_index, int *idx, int *cell_count, int *content_offset, |
| 656 | int *ptr_offset) { |
| 657 | while (*idx < child_count - SKIP_ONE) { |
| 658 | uint8_t tbuf[INTERIOR_CELL_BUF]; |
| 659 | uint8_t *heap_cell = NULL; |
| 660 | int clen = build_interior_cell(&children[*idx], is_index, tbuf, &heap_cell); |
| 661 | uint8_t *cell_data = heap_cell ? heap_cell : tbuf; |
| 662 | |
| 663 | int available = *content_offset - *ptr_offset - CELL_PTR_SIZE; |
| 664 | if (clen > available && *cell_count > 0) { |
| 665 | free(heap_cell); |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | *content_offset -= clen; |
| 670 | memcpy(page + *content_offset, cell_data, clen); |
| 671 | put_u16(page + *ptr_offset, (uint16_t)*content_offset); |
| 672 | *ptr_offset += CELL_PTR_SIZE; |
| 673 | (*cell_count)++; |
| 674 | free(heap_cell); |
| 675 | (*idx)++; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | static uint32_t pb_build_interior(PageBuilder *pb, bool is_index) { |
| 680 | if (!pb->leaves) { |
no test coverage detected