converter is passed as self to outlive the scope of Converter::Convert()
| 64 | |
| 65 | // converter is passed as self to outlive the scope of Converter::Convert() |
| 66 | SEXP ScheduleConvertTasks(RTasks& tasks, std::shared_ptr<Converter> self) { |
| 67 | // try altrep first |
| 68 | SEXP alt = altrep::MakeAltrepVector(chunked_array_); |
| 69 | if (!Rf_isNull(alt)) { |
| 70 | return alt; |
| 71 | } |
| 72 | |
| 73 | // otherwise use the Converter api: |
| 74 | |
| 75 | // allocating the R vector upfront |
| 76 | SEXP out = PROTECT(Allocate(chunked_array_->length())); |
| 77 | |
| 78 | // for each array, fill the relevant slice of `out`, potentially in parallel |
| 79 | R_xlen_t k = 0, i = 0; |
| 80 | for (const auto& array : chunked_array_->chunks()) { |
| 81 | auto n_chunk = array->length(); |
| 82 | |
| 83 | tasks.Append(Parallel(), [=] { |
| 84 | if (array->null_count() == n_chunk) { |
| 85 | return self->Ingest_all_nulls(out, k, n_chunk); |
| 86 | } else { |
| 87 | return self->Ingest_some_nulls(out, array, k, n_chunk, i); |
| 88 | } |
| 89 | }); |
| 90 | |
| 91 | k += n_chunk; |
| 92 | i++; |
| 93 | } |
| 94 | |
| 95 | UNPROTECT(1); |
| 96 | return out; |
| 97 | } |
| 98 | |
| 99 | // Converter factory |
| 100 | static std::shared_ptr<Converter> Make( |
no test coverage detected