converter is passed as self to outlive the scope of Converter::Convert()
| 71 | |
| 72 | // converter is passed as self to outlive the scope of Converter::Convert() |
| 73 | SEXP ScheduleConvertTasks(RTasks& tasks, std::shared_ptr<Converter> self) { |
| 74 | // try altrep first |
| 75 | SEXP alt = altrep::MakeAltrepVector(chunked_array_); |
| 76 | if (!Rf_isNull(alt)) { |
| 77 | return alt; |
| 78 | } |
| 79 | |
| 80 | // otherwise use the Converter api: |
| 81 | |
| 82 | // allocating the R vector upfront |
| 83 | SEXP out = PROTECT(Allocate(chunked_array_->length())); |
| 84 | |
| 85 | // for each array, fill the relevant slice of `out`, potentially in parallel |
| 86 | R_xlen_t k = 0, i = 0; |
| 87 | for (const auto& array : chunked_array_->chunks()) { |
| 88 | auto n_chunk = array->length(); |
| 89 | |
| 90 | tasks.Append(Parallel(), [=] { |
| 91 | if (array->null_count() == n_chunk) { |
| 92 | return self->Ingest_all_nulls(out, k, n_chunk); |
| 93 | } else { |
| 94 | return self->Ingest_some_nulls(out, array, k, n_chunk, i); |
| 95 | } |
| 96 | }); |
| 97 | |
| 98 | k += n_chunk; |
| 99 | i++; |
| 100 | } |
| 101 | |
| 102 | UNPROTECT(1); |
| 103 | return out; |
| 104 | } |
| 105 | |
| 106 | // Convert a slice of the data this converter was built for (e.g. one element of a |
| 107 | // list array) to a standalone R vector, reusing the decisions this converter made |
no test coverage detected