[前][次][番号順一覧][スレッド一覧]

ruby-changes:65099

From: Nobuyoshi <ko1@a...>
Date: Sun, 31 Jan 2021 19:29:23 +0900 (JST)
Subject: [ruby-changes:65099] 22b8ddfd10 (master): Split `mnew` into unbound and callable

https://git.ruby-lang.org/ruby.git/commit/?id=22b8ddfd10

From 22b8ddfd1049c3fd1e368684c4fd03bceb041b3a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
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(-)

diff --git a/proc.c b/proc.c
index a4ea995..d1e8358 100644
--- a/proc.c
+++ b/proc.c
@@ -1709,20 +1709,26 @@ mnew_from_me(const rb_method_entry_t *me, VALUE klass, VALUE iclass, https://github.com/ruby/ruby/blob/trunk/proc.c#L1709
 }
 
 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) https://github.com/ruby/ruby/blob/trunk/proc.c#L1966
         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) https://github.com/ruby/ruby/blob/trunk/proc.c#L2127
     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) https://github.com/ruby/ruby/blob/trunk/proc.c#L2144
     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.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]