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

ruby-changes:58033

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 30 Sep 2019 10:33:14 +0900 (JST)
Subject: [ruby-changes:58033] 167e6b48f1 (master): refactor reduce METHOD_ENTRY_FLAGS_COPY

https://git.ruby-lang.org/ruby.git/commit/?id=167e6b48f1

From 167e6b48f1b321d671998728adf5a0db06d24445 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Wed, 25 Sep 2019 15:52:02 +0900
Subject: refactor reduce METHOD_ENTRY_FLAGS_COPY

Make things more immutable.

diff --git a/vm_method.c b/vm_method.c
index 6d05222..3249cb7 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -478,9 +478,11 @@ method_definition_addref_complement(rb_method_definition_t *def) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L478
 }
 
 static rb_method_entry_t *
-rb_method_entry_alloc(ID called_id, VALUE owner, VALUE defined_class, const rb_method_definition_t *def)
+rb_method_entry_alloc(VALUE flags, ID called_id, VALUE owner, VALUE defined_class, const rb_method_definition_t *def)
 {
+    rb_method_entry_t tmp = { flags, };
     rb_method_entry_t *me = (rb_method_entry_t *)rb_imemo_new(imemo_ment, (VALUE)def, (VALUE)called_id, owner, defined_class);
+    METHOD_ENTRY_FLAGS_COPY(me, &tmp);
     return me;
 }
 
@@ -501,8 +503,15 @@ filter_defined_class(VALUE klass) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L503
 MJIT_FUNC_EXPORTED rb_method_entry_t *
 rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, const rb_method_definition_t *def)
 {
-    rb_method_entry_t *me = rb_method_entry_alloc(called_id, klass, filter_defined_class(klass), def);
-    METHOD_ENTRY_FLAGS_SET(me, visi, ruby_running ? FALSE : TRUE);
+    rb_method_entry_t tmp = { 0, };
+    METHOD_ENTRY_FLAGS_SET(&tmp, visi, !ruby_running);
+    rb_method_entry_t *me =
+        rb_method_entry_alloc(
+            tmp.flags,
+            called_id,
+            klass,
+            filter_defined_class(klass),
+            def);
     if (def != NULL) method_definition_reset(me);
     return me;
 }
@@ -510,10 +519,12 @@ rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, c https://github.com/ruby/ruby/blob/trunk/vm_method.c#L519
 const rb_method_entry_t *
 rb_method_entry_clone(const rb_method_entry_t *src_me)
 {
-    rb_method_entry_t *me = rb_method_entry_alloc(src_me->called_id, src_me->owner, src_me->defined_class,
-						  method_definition_addref(src_me->def));
-    METHOD_ENTRY_FLAGS_COPY(me, src_me);
-    return me;
+    return rb_method_entry_alloc(
+        src_me->flags,
+        src_me->called_id,
+        src_me->owner,
+        src_me->defined_class,
+        method_definition_addref(src_me->def));
 }
 
 MJIT_FUNC_EXPORTED const rb_callable_method_entry_t *
@@ -538,8 +549,12 @@ rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID cal https://github.com/ruby/ruby/blob/trunk/vm_method.c#L549
     else {
 	def = method_definition_addref_complement((rb_method_definition_t *)def);
     }
-    me = rb_method_entry_alloc(called_id, src_me->owner, defined_class, def);
-    METHOD_ENTRY_FLAGS_COPY(me, src_me);
+    me = rb_method_entry_alloc(
+        src_me->flags,
+        called_id,
+        src_me->owner,
+        defined_class,
+        def);
 
     VM_ASSERT(RB_TYPE_P(me->owner, T_MODULE));
 
@@ -555,11 +570,13 @@ make_method_entry_refined(VALUE owner, rb_method_entry_t *me) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L570
     else {
 	rb_vm_check_redefinition_opt_method(me, me->owner);
         rb_method_entry_t *orig_me =
-	    rb_method_entry_alloc(me->called_id, me->owner,
-				  me->defined_class ?
-				  me->defined_class : owner,
-				  method_definition_addref(me->def));
-        METHOD_ENTRY_FLAGS_COPY(orig_me, me);
+            rb_method_entry_alloc(
+                me->flags,
+                me->called_id,
+                me->owner,
+                me->defined_class ?
+                me->defined_class : owner,
+                method_definition_addref(me->def));
         const rb_method_definition_t *def =
             rb_method_definition_create(
                 VM_METHOD_TYPE_REFINED,
@@ -570,12 +587,12 @@ make_method_entry_refined(VALUE owner, rb_method_entry_t *me) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L587
                 }
             );
         rb_method_entry_t *new_me =
-            rb_method_entry_create(
+            rb_method_entry_alloc(
+                me->flags,
                 me->called_id,
                 me->owner,
                 me->defined_class,
                 def);
-        METHOD_ENTRY_FLAGS_COPY(new_me, me);
         METHOD_ENTRY_VISI_SET(new_me, METHOD_VISI_PUBLIC);
         return new_me;
     }
-- 
cgit v0.10.2


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

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