diff options
author | Nobuyoshi Nakada <[email protected]> | 2021-01-31 18:11:59 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-01-31 18:48:28 +0900 |
commit | 22b8ddfd1049c3fd1e368684c4fd03bceb041b3a (patch) | |
tree | 6bb10472df6fbbbb233f3bf317535f2736e2abe3 /proc.c | |
parent | e44870c2253a47c0fa989a4a188a7164735fec03 (diff) |
Split `mnew` into unbound and callable
It always branches by `obj` is `Qundef` or not, which is invariant
for each functions; `obj_method` is the latter, and the other two
are the former.
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -1709,20 +1709,26 @@ mnew_from_me(const rb_method_entry_t *me, VALUE klass, VALUE iclass, } static VALUE -mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope) +mnew_callable(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope) { const rb_method_entry_t *me; VALUE iclass = Qnil; - if (obj == Qundef) { /* UnboundMethod */ - me = rb_method_entry_with_refinements(klass, id, &iclass); - } - else { - me = (rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass, id, &iclass); - } + ASSUME(obj != Qundef); + me = (rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass, id, &iclass); return mnew_from_me(me, klass, iclass, obj, id, mclass, scope); } +static VALUE +mnew_unbound(VALUE klass, ID id, VALUE mclass, int scope) +{ + const rb_method_entry_t *me; + VALUE iclass = Qnil; + + me = rb_method_entry_with_refinements(klass, id, &iclass); + return mnew_from_me(me, klass, iclass, Qundef, id, mclass, scope); +} + static inline VALUE method_entry_defined_class(const rb_method_entry_t *me) { @@ -1960,7 +1966,7 @@ obj_method(VALUE obj, VALUE vid, int scope) if (m) return m; rb_method_name_error(klass, vid); } - return mnew(klass, obj, id, mclass, scope); + return mnew_callable(klass, obj, id, mclass, scope); } /* @@ -2121,7 +2127,7 @@ rb_mod_instance_method(VALUE mod, VALUE vid) if (!id) { rb_method_name_error(mod, vid); } - return mnew(mod, Qundef, id, rb_cUnboundMethod, FALSE); + return mnew_unbound(mod, id, rb_cUnboundMethod, FALSE); } /* @@ -2138,7 +2144,7 @@ rb_mod_public_instance_method(VALUE mod, VALUE vid) if (!id) { rb_method_name_error(mod, vid); } - return mnew(mod, Qundef, id, rb_cUnboundMethod, TRUE); + return mnew_unbound(mod, id, rb_cUnboundMethod, TRUE); } /* |