Skip to content

Commit 29c5518

Browse files
committed
Simplify vec_ptype() helper
1 parent ce228ff commit 29c5518

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

src/ptype2.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ r_obj* vec_ptype2_impl(
6868
// When `x` and `y` are `NULL`, keep using `x` name (1)
6969
// When `x` is `NULL` but `y` isn't, switch to `y` name (0)
7070
*left = y_type == VCTRS_TYPE_null;
71-
return vec_ptype2_from_unspecified(y, p_y_arg, x_type, call, s3_fallback);
71+
return vec_ptype_or_s3_fallback(y, p_y_arg, x_type, call, s3_fallback);
7272
}
7373
if (y_type == VCTRS_TYPE_null) {
7474
// When `x` and `y` are `NULL`, keep using `x` name (1)
7575
// When `y` is `NULL` but `x` isn't, keep using `x` name (1)
7676
*left = 1;
77-
return vec_ptype2_from_unspecified(x, p_x_arg, x_type, call, s3_fallback);
77+
return vec_ptype_or_s3_fallback(x, p_x_arg, x_type, call, s3_fallback);
7878
}
7979

8080
if (x_type == VCTRS_TYPE_unspecified) {
81-
return vec_ptype2_from_unspecified(y, p_y_arg, y_type, call, s3_fallback);
81+
return vec_ptype_or_s3_fallback(y, p_y_arg, y_type, call, s3_fallback);
8282
}
8383
if (y_type == VCTRS_TYPE_unspecified) {
84-
return vec_ptype2_from_unspecified(x, p_x_arg, x_type, call, s3_fallback);
84+
return vec_ptype_or_s3_fallback(x, p_x_arg, x_type, call, s3_fallback);
8585
}
8686

8787
if (x_type == VCTRS_TYPE_scalar) {
@@ -225,25 +225,21 @@ r_obj* vec_ptype2_switch_native(
225225
}
226226

227227
/**
228-
* Return non-unspecified type.
228+
* Return `vec_ptype()`, allowing for common class fallback
229229
*
230-
* This is normally the `vec_ptype()` of the other input, but if the
231-
* common class fallback is enabled we return the `vec_ptype2()` of
232-
* this input with itself. This way we may return a fallback sentinel which can be
233-
* treated specially, for instance in `vec_c(NA, x, NA)`.
230+
* This is normally the `vec_ptype()` of the input, but if the common class
231+
* fallback is enabled we return the `vec_ptype2()` of this input with itself.
232+
* This way we may return a fallback sentinel which can be treated specially,
233+
* for instance in `vec_c(NA, x, NA)`.
234234
*/
235-
r_obj* vec_ptype2_from_unspecified(
235+
r_obj* vec_ptype_or_s3_fallback(
236236
r_obj* x,
237237
struct vctrs_arg* p_x_arg,
238238
enum vctrs_type x_type,
239239
struct r_lazy call,
240240
enum s3_fallback s3_fallback
241241
) {
242-
if (x_type == VCTRS_TYPE_unspecified || x_type == VCTRS_TYPE_null) {
243-
return vec_ptype(x, p_x_arg, call);
244-
}
245-
246-
if (s3_fallback) {
242+
if (s3_fallback == S3_FALLBACK_true && x_type == VCTRS_TYPE_s3) {
247243
int _;
248244
return vec_ptype2(
249245
x,

src/ptype2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bool vec_is_coercible(
3030

3131
enum s3_fallback s3_fallback_from_opts(r_obj* opts);
3232

33-
r_obj* vec_ptype2_from_unspecified(
33+
r_obj* vec_ptype_or_s3_fallback(
3434
r_obj* x,
3535
struct vctrs_arg* p_x_arg,
3636
enum vctrs_type x_type,

src/type-data-frame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ r_obj* df_ptype2_match(
587587

588588
r_obj* type;
589589
if (dup == r_globals.na_int) {
590-
type = vec_ptype2_from_unspecified(
590+
type = vec_ptype_or_s3_fallback(
591591
x_col,
592592
p_x_col_arg,
593593
vec_typeof(x_col),
@@ -624,7 +624,7 @@ r_obj* df_ptype2_match(
624624
y_col_arg_loc = j;
625625
r_obj* y_col = r_list_get(y, j);
626626

627-
r_obj* type = vec_ptype2_from_unspecified(
627+
r_obj* type = vec_ptype_or_s3_fallback(
628628
y_col,
629629
p_y_col_arg,
630630
vec_typeof(y_col),

0 commit comments

Comments
 (0)