| 639 | } |
| 640 | |
| 641 | static R_xlen_t Get_region(SEXP alt, R_xlen_t start, R_xlen_t n, int* buf) { |
| 642 | // If we have data2, we can just copy the region into buf |
| 643 | // using the standard Get_region for this R type |
| 644 | if (Base::IsMaterialized(alt)) { |
| 645 | return Standard_Get_region<int>(Representation(alt), start, n, buf); |
| 646 | } |
| 647 | |
| 648 | auto chunked_array = GetChunkedArray(alt); |
| 649 | |
| 650 | // get out if there is nothing to do |
| 651 | auto chunked_array_size = chunked_array->length(); |
| 652 | if (start >= chunked_array_size) return 0; |
| 653 | |
| 654 | auto slice = GetChunkedArray(alt)->Slice(start, n); |
| 655 | |
| 656 | if (WasUnified(alt)) { |
| 657 | int j = 0; |
| 658 | |
| 659 | // find out which is the first chunk of the chunk array |
| 660 | // that is present in the slice, because the main loop |
| 661 | // needs to refer to the correct transpose buffers |
| 662 | int64_t k = 0; |
| 663 | for (; j < chunked_array->num_chunks(); j++) { |
| 664 | auto nj = chunked_array->chunk(j)->length(); |
| 665 | if (k + nj > start) { |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | k += nj; |
| 670 | } |
| 671 | |
| 672 | int* out = buf; |
| 673 | for (const auto& array : slice->chunks()) { |
| 674 | const auto& indices = |
| 675 | internal::checked_cast<const DictionaryArray&>(*array).indices(); |
| 676 | |
| 677 | // using the transpose data for this chunk |
| 678 | const auto* transpose_data = |
| 679 | reinterpret_cast<const int32_t*>(GetArrayTransposed(alt, j)->data()); |
| 680 | auto transpose = [transpose_data](int64_t x) { return transpose_data[x]; }; |
| 681 | |
| 682 | GetRegionDispatch(array, indices, transpose, out); |
| 683 | |
| 684 | out += array->length(); |
| 685 | j++; |
| 686 | } |
| 687 | |
| 688 | } else { |
| 689 | // simpler case, identity transpose |
| 690 | auto transpose = [](int64_t x) { return static_cast<int>(x); }; |
| 691 | |
| 692 | int* out = buf; |
| 693 | for (const auto& array : slice->chunks()) { |
| 694 | const auto& indices = |
| 695 | internal::checked_cast<const DictionaryArray&>(*array).indices(); |
| 696 | |
| 697 | GetRegionDispatch(array, indices, transpose, out); |
| 698 | |