1919#include "order-groups.h"
2020#include "order-truelength.h"
2121#include "order-sortedness.h"
22+ #include "order-transform.h"
2223
2324// -----------------------------------------------------------------------------
2425
183184
184185// -----------------------------------------------------------------------------
185186
186- static SEXP vec_order (SEXP x , SEXP decreasing , SEXP na_last );
187+ static SEXP vec_order (SEXP x , SEXP decreasing , SEXP na_last , SEXP chr_transform );
187188
188189// [[ register() ]]
189- SEXP vctrs_order (SEXP x , SEXP direction , SEXP na_value ) {
190+ SEXP vctrs_order (SEXP x , SEXP direction , SEXP na_value , SEXP chr_transform ) {
190191 SEXP decreasing = PROTECT (parse_direction (direction ));
191192 SEXP na_last = PROTECT (parse_na_value (na_value ));
192193
193- SEXP out = vec_order (x , decreasing , na_last );
194+ SEXP out = vec_order (x , decreasing , na_last , chr_transform );
194195
195196 UNPROTECT (2 );
196197 return out ;
197198}
198199
199200
200- static SEXP vec_order_impl (SEXP x , SEXP decreasing , SEXP na_last , bool locations );
201+ static SEXP vec_order_impl (SEXP x ,
202+ SEXP decreasing ,
203+ SEXP na_last ,
204+ SEXP chr_transform ,
205+ bool locations );
201206
202207static
203- SEXP vec_order (SEXP x , SEXP decreasing , SEXP na_last ) {
204- return vec_order_impl (x , decreasing , na_last , false);
208+ SEXP vec_order (SEXP x , SEXP decreasing , SEXP na_last , SEXP chr_transform ) {
209+ return vec_order_impl (x , decreasing , na_last , chr_transform , false);
205210}
206211
207212// -----------------------------------------------------------------------------
208213
209- static SEXP vec_order_locs (SEXP x , SEXP decreasing , SEXP na_last );
214+ static SEXP vec_order_locs (SEXP x , SEXP decreasing , SEXP na_last , SEXP chr_transform );
210215
211216// [[ register() ]]
212- SEXP vctrs_order_locs (SEXP x , SEXP direction , SEXP na_value ) {
217+ SEXP vctrs_order_locs (SEXP x , SEXP direction , SEXP na_value , SEXP chr_transform ) {
213218 SEXP decreasing = PROTECT (parse_direction (direction ));
214219 SEXP na_last = PROTECT (parse_na_value (na_value ));
215220
216- SEXP out = vec_order_locs (x , decreasing , na_last );
221+ SEXP out = vec_order_locs (x , decreasing , na_last , chr_transform );
217222
218223 UNPROTECT (2 );
219224 return out ;
220225}
221226
222227
223228static
224- SEXP vec_order_locs (SEXP x , SEXP decreasing , SEXP na_last ) {
225- return vec_order_impl (x , decreasing , na_last , true);
229+ SEXP vec_order_locs (SEXP x , SEXP decreasing , SEXP na_last , SEXP chr_transform ) {
230+ return vec_order_impl (x , decreasing , na_last , chr_transform , true);
226231}
227232
228233// -----------------------------------------------------------------------------
@@ -258,7 +263,7 @@ static void vec_order_switch(SEXP x,
258263 * the locations in `x` corresponding to each key.
259264 */
260265static
261- SEXP vec_order_impl (SEXP x , SEXP decreasing , SEXP na_last , bool locations ) {
266+ SEXP vec_order_impl (SEXP x , SEXP decreasing , SEXP na_last , SEXP chr_transform , bool locations ) {
262267 int n_prot = 0 ;
263268 int * p_n_prot = & n_prot ;
264269
@@ -269,6 +274,7 @@ SEXP vec_order_impl(SEXP x, SEXP decreasing, SEXP na_last, bool locations) {
269274
270275 SEXP proxy = PROTECT_N (vec_proxy_order (x ), p_n_prot );
271276 proxy = PROTECT_N (vec_normalize_encoding (proxy ), p_n_prot );
277+ proxy = PROTECT_N (proxy_chr_transform (proxy , chr_transform ), p_n_prot );
272278
273279 r_ssize size = vec_size (proxy );
274280 const enum vctrs_type type = vec_proxy_typeof (proxy );
@@ -3526,7 +3532,14 @@ void df_order_internal(SEXP x,
35263532
35273533 // Iterate over remaining columns by group chunk
35283534 for (r_ssize i = 1 ; i < n_cols ; ++ i ) {
3529- col = VECTOR_ELT (x , i );
3535+ // Get the number of group chunks from previous column group info
3536+ struct group_info * p_group_info_pre = groups_current (p_group_infos );
3537+ r_ssize n_groups = p_group_info_pre -> n_groups ;
3538+
3539+ // If there were no ties, we are completely done
3540+ if (n_groups == size ) {
3541+ break ;
3542+ }
35303543
35313544 if (!recycle_decreasing ) {
35323545 col_decreasing = p_decreasing [i ];
@@ -3541,15 +3554,7 @@ void df_order_internal(SEXP x,
35413554 // processed at least one column.
35423555 int * p_o_col = p_order -> p_data ;
35433556
3544- // Get the number of group chunks from previous column group info
3545- struct group_info * p_group_info_pre = groups_current (p_group_infos );
3546- r_ssize n_groups = p_group_info_pre -> n_groups ;
3547-
3548- // If there were no ties, we are completely done
3549- if (n_groups == size ) {
3550- break ;
3551- }
3552-
3557+ col = VECTOR_ELT (x , i );
35533558 type = vec_proxy_typeof (col );
35543559
35553560 // If we are on the rerun pass, flip this back off so the
@@ -3558,7 +3563,7 @@ void df_order_internal(SEXP x,
35583563 rerun_complex = rerun_complex ? false : true;
35593564 }
35603565
3561- // Pre sort unique characters once for the whole column
3566+ // Pre- sort unique characters once for the whole column
35623567 if (type == vctrs_type_character ) {
35633568 const SEXP * p_col = STRING_PTR_RO (col );
35643569
0 commit comments