From 22b8ddfd1049c3fd1e368684c4fd03bceb041b3a Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 31 Jan 2021 18:11:59 +0900 Subject: 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. --- proc.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'proc.c') diff --git a/proc.c b/proc.c index a4ea99598e..d1e8358bea 100644 --- a/proc.c +++ b/proc.c @@ -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); } /* -- cgit v1.2.1