Conversation
lionel-
left a comment
There was a problem hiding this comment.
The PR is missing benchmarks to describe what is gained from moving all this code to C.
What would be needed from vctrs to be able to delegate subsetting to it?
| // x_names: names of x | ||
| // n_old: number of elements with some property | ||
| // j_max: maximum value of j | ||
| // j_/j: SEXP and native version of bare vector |
There was a problem hiding this comment.
Use j_ffi vs j? This way it's immediately clear which does what.
|
|
||
| // Compute j from j_, converting 1-based j_ to zero-based j | ||
| R_xlen_t n_j = Rf_xlength(j_); | ||
| R_xlen_t* j = (R_xlen_t*)R_alloc(n_j + 1, sizeof(R_xlen_t)); |
There was a problem hiding this comment.
Is there a reason not to use a raw vector here? Just asking because we usually renounce to manage memory only in very specific cases.
There was a problem hiding this comment.
Same remark for allocs below. Another reason to manage memory manually is that it makes it clearer when things are not needed anymore, so this has a self-documenting value.
| } | ||
|
|
||
| // Allocate output vector and output names with final size | ||
| SEXP xo = Rf_allocVector(VECSXP, n_xo); |
| SEXP xo = Rf_allocVector(VECSXP, n_xo); | ||
| Rf_copyMostAttrib(x, xo); | ||
|
|
||
| SEXP xo_names = Rf_allocVector(STRSXP, n_xo); |
|
|
||
| // Compute j from j_, converting 1-based j_ to zero-based j | ||
| R_xlen_t n_j = Rf_xlength(j_); | ||
| R_xlen_t* j = (R_xlen_t*)R_alloc(n_j + 1, sizeof(R_xlen_t)); |
There was a problem hiding this comment.
Could you have used vec_as_location() upstream to avoid having to deal with double vectors? I imagine tibble doesn't need support for long vectors in the column dimension.
| // Add sentinel value | ||
| j[n_j] = -1; | ||
|
|
||
| // Compute j_max and n_old |
|
|
||
| // Set output row names | ||
| // FIXME: Reuse original vector? | ||
| SEXP new_row_names_ = Rf_allocVector(INTSXP, 2); |
For #1353.