| 669 | } |
| 670 | |
| 671 | static sz_bool_t sz_py_replace_u32_tape_view_allocator(Strs *strs, sz_memory_allocator_t *allocator) { |
| 672 | // Convert view to tape by copying the data |
| 673 | struct u32_tape_view_t *view = &strs->data.u32_tape_view; |
| 674 | sz_u32_t const slice_start_offset = view->offsets[0]; |
| 675 | sz_size_t const string_data_size = (sz_size_t)(view->offsets[view->count] - slice_start_offset); |
| 676 | sz_size_t const offsets_size = (view->count + 1) * sizeof(sz_u32_t); |
| 677 | |
| 678 | // Allocate new string data with new allocator |
| 679 | sz_ptr_t new_string_data = NULL; |
| 680 | if (string_data_size > 0) { |
| 681 | new_string_data = (sz_ptr_t)allocator->allocate(string_data_size, allocator->handle); |
| 682 | if (!new_string_data) return sz_false_k; |
| 683 | memcpy(new_string_data, view->data + slice_start_offset, string_data_size); |
| 684 | } |
| 685 | |
| 686 | // Allocate new offsets array and adjust to be relative to slice start |
| 687 | sz_u32_t *new_offsets = NULL; |
| 688 | if (offsets_size > 0) { |
| 689 | new_offsets = (sz_u32_t *)allocator->allocate(offsets_size, allocator->handle); |
| 690 | if (!new_offsets) { |
| 691 | if (string_data_size > 0) allocator->free(new_string_data, string_data_size, allocator->handle); |
| 692 | return sz_false_k; |
| 693 | } |
| 694 | for (sz_size_t i = 0; i <= view->count; ++i) new_offsets[i] = view->offsets[i] - slice_start_offset; |
| 695 | } |
| 696 | |
| 697 | // Release parent reference if any |
| 698 | Py_XDECREF(view->parent); |
| 699 | |
| 700 | // Convert to tape layout |
| 701 | strs->layout = STRS_U32_TAPE; |
| 702 | strs->data.u32_tape.count = view->count; |
| 703 | strs->data.u32_tape.data = new_string_data; |
| 704 | strs->data.u32_tape.offsets = new_offsets; |
| 705 | strs->data.u32_tape.allocator = *allocator; |
| 706 | return sz_true_k; |
| 707 | } |
| 708 | |
| 709 | static sz_bool_t sz_py_replace_u64_tape_view_allocator(Strs *strs, sz_memory_allocator_t *allocator) { |
| 710 | // Convert view to tape by copying the data |
no test coverage detected
searching dependent graphs…