Skip to content

Commit

Permalink
Introduce rb_vm_call_with_refinements to DRY up a few calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Oct 1, 2021
1 parent 0ad3ed5 commit 9b04909
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
14 changes: 14 additions & 0 deletions vm_eval.c
Expand Up @@ -57,6 +57,20 @@ rb_vm_call0(rb_execution_context_t *ec, VALUE recv, ID id, int argc, const VALUE
return vm_call0_body(ec, &calling, argv);
}

MJIT_FUNC_EXPORTED VALUE
rb_vm_call_with_refinements(rb_execution_context_t *ec, VALUE recv, ID id, int argc, const VALUE *argv, int kw_splat)
{
const rb_callable_method_entry_t *me =
rb_callable_method_entry_with_refinements(CLASS_OF(recv), id, NULL);
if (me) {
return rb_vm_call0(ec, recv, id, argc, argv, me, kw_splat);
}
else {
/* fallback to funcall (e.g. method_missing) */
return rb_funcallv(recv, id, argc, argv);
}
}

static inline VALUE
vm_call0_cc(rb_execution_context_t *ec, VALUE recv, ID id, int argc, const VALUE *argv, const struct rb_callcache *cc, int kw_splat)
{
Expand Down
31 changes: 4 additions & 27 deletions vm_insnhelper.c
Expand Up @@ -2087,6 +2087,7 @@ rb_eql_opt(VALUE obj1, VALUE obj2)
#endif // MJIT_HEADER

extern VALUE rb_vm_call0(rb_execution_context_t *ec, VALUE, ID, int, const VALUE*, const rb_callable_method_entry_t *, int kw_splat);
extern VALUE rb_vm_call_with_refinements(rb_execution_context_t *, VALUE, ID, int, const VALUE *, int);

static VALUE
check_match(rb_execution_context_t *ec, VALUE pattern, VALUE target, enum vm_check_match_type type)
Expand All @@ -2100,15 +2101,7 @@ check_match(rb_execution_context_t *ec, VALUE pattern, VALUE target, enum vm_che
}
/* fall through */
case VM_CHECKMATCH_TYPE_CASE: {
const rb_callable_method_entry_t *me =
rb_callable_method_entry_with_refinements(CLASS_OF(pattern), idEqq, NULL);
if (me) {
return rb_vm_call0(ec, pattern, idEqq, 1, &target, me, RB_NO_KEYWORDS);
}
else {
/* fallback to funcall (e.g. method_missing) */
return rb_funcallv(pattern, idEqq, 1, &target);
}
return rb_vm_call_with_refinements(ec, pattern, idEqq, 1, &target, RB_NO_KEYWORDS);
}
default:
rb_bug("check_match: unreachable");
Expand Down Expand Up @@ -4675,15 +4668,7 @@ vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
}
}
else {
VALUE ary = rb_ary_new4(num, ptr);
const rb_callable_method_entry_t *me =
rb_callable_method_entry_with_refinements(rb_cArray, idMax, NULL);
if (me) {
return rb_vm_call0(ec, ary, idMax, 0, NULL, me, RB_NO_KEYWORDS);
}
else {
return rb_funcall(ary, idMax, 0);
}
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idMax, 0, NULL, RB_NO_KEYWORDS);
}
}

Expand All @@ -4708,15 +4693,7 @@ vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
}
}
else {
VALUE ary = rb_ary_new4(num, ptr);
const rb_callable_method_entry_t *me =
rb_callable_method_entry_with_refinements(rb_cArray, idMin, NULL);
if (me) {
return rb_vm_call0(ec, ary, idMin, 0, NULL, me, RB_NO_KEYWORDS);
}
else {
return rb_funcall(ary, idMin, 0);
}
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idMin, 0, NULL, RB_NO_KEYWORDS);
}
}

Expand Down

0 comments on commit 9b04909

Please sign in to comment.