| 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 |
| 711 | struct u64_tape_view_t *view = &strs->data.u64_tape_view; |
| 712 | sz_u64_t const slice_start_offset = view->offsets[0]; |
| 713 | sz_size_t const string_data_size = (sz_size_t)(view->offsets[view->count] - slice_start_offset); |
| 714 | sz_size_t const offsets_size = (view->count + 1) * sizeof(sz_u64_t); |
| 715 | |
| 716 | // Allocate new string data with new allocator |
| 717 | sz_ptr_t new_string_data = NULL; |
| 718 | if (string_data_size > 0) { |
| 719 | new_string_data = (sz_ptr_t)allocator->allocate(string_data_size, allocator->handle); |
| 720 | if (!new_string_data) return sz_false_k; |
| 721 | memcpy(new_string_data, view->data + slice_start_offset, string_data_size); |
| 722 | } |
| 723 | |
| 724 | // Allocate new offsets array and adjust to be relative to slice start |
| 725 | sz_u64_t *new_offsets = NULL; |
| 726 | if (offsets_size > 0) { |
| 727 | new_offsets = (sz_u64_t *)allocator->allocate(offsets_size, allocator->handle); |
| 728 | if (!new_offsets) { |
| 729 | if (string_data_size > 0) allocator->free(new_string_data, string_data_size, allocator->handle); |
| 730 | return sz_false_k; |
| 731 | } |
| 732 | for (sz_size_t i = 0; i <= view->count; ++i) new_offsets[i] = view->offsets[i] - slice_start_offset; |
| 733 | } |
| 734 | |
| 735 | // Release parent reference if any |
| 736 | Py_XDECREF(view->parent); |
| 737 | |
| 738 | // Convert to tape layout |
| 739 | strs->layout = STRS_U64_TAPE; |
| 740 | strs->data.u64_tape.count = view->count; |
| 741 | strs->data.u64_tape.data = new_string_data; |
| 742 | strs->data.u64_tape.offsets = new_offsets; |
| 743 | strs->data.u64_tape.allocator = *allocator; |
| 744 | return sz_true_k; |
| 745 | } |
| 746 | |
| 747 | static sz_bool_t sz_py_replace_fragmented_allocator(Strs *strs, sz_memory_allocator_t *old_allocator, |
| 748 | sz_memory_allocator_t *allocator) { |
no test coverage detected
searching dependent graphs…