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

ruby-changes:61628

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 9 Jun 2020 09:53:25 +0900 (JST)
Subject: [ruby-changes:61628] 324038c66e (master): eliminate C99 compound literals

https://git.ruby-lang.org/ruby.git/commit/?id=324038c66e

From 324038c66edc947a7738440621587575355087a4 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: Thu, 4 Jun 2020 13:03:13 +0900
Subject: eliminate C99 compound literals

Ko1 prefers variables be assgined, instead of bare literals in function
arguments.

diff --git a/vm_eval.c b/vm_eval.c
index a03c614..8265091 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -45,20 +45,18 @@ static VALUE vm_call0_body(rb_execution_context_t* ec, struct rb_calling_info *c https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L45
 MJIT_FUNC_EXPORTED VALUE
 rb_vm_call0(rb_execution_context_t *ec, VALUE recv, ID id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me, int kw_splat)
 {
-    return vm_call0_body(
-        ec,
-        &(struct rb_calling_info) {
-            .block_handler = VM_BLOCK_HANDLER_NONE,
-            .recv = recv,
-            .argc = argc,
-            .kw_splat = kw_splat,
-        },
-        &(struct rb_call_data) {
-            .ci = &VM_CI_ON_STACK(id, kw_splat ? VM_CALL_KW_SPLAT : 0, argc, NULL),
-            .cc = &VM_CC_ON_STACK(Qfalse, vm_call_general, { 0 }, me),
-        },
-        argv
-    );
+    struct rb_calling_info calling = {
+        .block_handler = VM_BLOCK_HANDLER_NONE,
+        .recv = recv,
+        .argc = argc,
+        .kw_splat = kw_splat,
+    };
+    struct rb_call_data cd = {
+        .ci = &VM_CI_ON_STACK(id, kw_splat ? VM_CALL_KW_SPLAT : 0, argc, NULL),
+        .cc = &VM_CC_ON_STACK(Qfalse, vm_call_general, { 0 }, me),
+    };
+
+    return vm_call0_body(ec, &calling, &cd, argv);
 }
 
 static VALUE
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index e4d58f9..a9ce512 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -2685,11 +2685,13 @@ aliased_callable_method_entry(const rb_callable_method_entry_t *me) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2685
 static VALUE
 vm_call_alias(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_calling_info *calling, struct rb_call_data *cd)
 {
-    return vm_call_method_each_type(ec, cfp, calling, &(struct rb_call_data) {
+    struct rb_call_data aliased = {
         .ci = cd->ci,
         .cc = &VM_CC_ON_STACK(Qundef, vm_call_general, { 0 },
             aliased_callable_method_entry(vm_cc_cme(cd->cc))),
-    });
+    };
+
+    return vm_call_method_each_type(ec, cfp, calling, &aliased);
 }
 
 static enum method_missing_reason
@@ -2759,13 +2761,15 @@ vm_call_symbol( https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2761
         }
     }
 
-    return vm_call_method(ec, reg_cfp, calling, &(struct rb_call_data) {
+    struct rb_call_data cd = {
         .ci = &VM_CI_ON_STACK(mid, flags, argc, vm_ci_kwarg(ci)),
         .cc = &VM_CC_ON_STACK(klass, vm_call_general, {
                 .method_missing_reason = missing_reason
               },
               rb_callable_method_entry_with_refinements(klass, mid, NULL)),
-    });
+    };
+
+    return vm_call_method(ec, reg_cfp, calling, &cd);
 }
 
 static VALUE
@@ -2880,11 +2884,13 @@ vm_call_method_missing_body(rb_execution_context_t *ec, rb_control_frame_t *reg_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2884
     INC_SP(1);
 
     ec->method_missing_reason = reason;
-    return vm_call_method(ec, reg_cfp, calling, &(struct rb_call_data) {
+    struct rb_call_data cd = {
         .ci = &VM_CI_ON_STACK(idMethodMissing, flag, argc, vm_ci_kwarg(orig_ci)),
         .cc = &VM_CC_ON_STACK(Qundef, vm_call_general, { 0 },
             rb_callable_method_entry_without_refinements(CLASS_OF(calling->recv), idMethodMissing, NULL)),
-    });
+    };
+
+    return vm_call_method(ec, reg_cfp, calling, &cd);
 }
 
 static VALUE
@@ -2909,10 +2915,12 @@ vm_call_zsuper(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_ca https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2915
         cme = refined_method_callable_without_refinement(cme);
     }
 
-    return vm_call_method_each_type(ec, cfp, calling, &(struct rb_call_data) {
+    struct rb_call_data zsuper = {
         .ci = cd->ci,
         .cc = &VM_CC_ON_STACK(Qundef, vm_call_general, { 0 }, cme),
-    });
+    };
+
+    return vm_call_method_each_type(ec, cfp, calling, &zsuper);
 }
 
 static inline VALUE
@@ -3017,13 +3025,14 @@ search_refined_method(rb_execution_context_t *ec, rb_control_frame_t *cfp, struc https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3025
 static VALUE
 vm_call_refined(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_calling_info *calling, struct rb_call_data *cd)
 {
-    const rb_callable_method_entry_t *cme = search_refined_method(ec, cfp, cd);
+    struct rb_call_data refined = {
+        .ci = cd->ci,
+        .cc = &VM_CC_ON_STACK(Qundef, vm_call_general, { 0 },
+                              search_refined_method(ec, cfp, cd)),
+    };
 
-    if (cme != NULL) {
-        return vm_call_method(ec, cfp, calling, &(struct rb_call_data) {
-            .ci = cd->ci,
-            .cc = &VM_CC_ON_STACK(Qundef, vm_call_general, { 0 }, cme),
-        });
+    if (vm_cc_cme(refined.cc)) {
+        return vm_call_method(ec, cfp, calling, &refined);
     }
     else {
         return vm_call_method_nome(ec, cfp, calling, cd);
@@ -3160,10 +3169,12 @@ vm_call_method(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_ca https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3169
 		    /* caching method info to dummy cc */
 		    VM_ASSERT(vm_cc_cme(cc) != NULL);
                     const struct rb_callcache cc_on_stack = *cc;
-                    return vm_call_method_each_type(ec, cfp, calling, &(struct rb_call_data) {
+                    struct rb_call_data dummy = {
                         .ci = ci,
                         .cc = &cc_on_stack,
-                    });
+                    };
+
+                    return vm_call_method_each_type(ec, cfp, calling, &dummy);
 		}
 	    }
             return vm_call_method_each_type(ec, cfp, calling, cd);
-- 
cgit v0.10.2


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

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