r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
489 stars 131 forks source link

Remove `LEVELS()` accessor #1726

Open lionel- opened 5 days ago

lionel- commented 5 days ago

Part of https://github.com/r-lib/rlang/issues/1706

LEVELS() was added in https://github.com/r-lib/rlang/pull/1187

Used to detect non-utf8 strings in r_obj_encode_utf8() and optimise the default case of no encoding conversion needed:

We could just call Encoding(x) <- "UTF8" from R. This will unconditionally clone the input vector unless it doesn't have any references. To preserve our optimisation, either of these would work:

My sense is that these new unconditional allocs would be bad for performance in dplyr. @DavisVaughan you added these optimisations for vctrs, could you confirm please?

lionel- commented 5 days ago

There's now https://github.com/wch/r-source/commit/0c753e41fc06bf5a8825657a5843104a93f28c12 so we should be able to preserve our optimisations.