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

ruby-changes:59623

From: Yusuke <ko1@a...>
Date: Sun, 5 Jan 2020 13:34:54 +0900 (JST)
Subject: [ruby-changes:59623] c7f01d889b (master): include/ruby/ruby.h: remove last_idx that is no longer variable

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

From c7f01d889becbeffc4254e1b0b7faecb80ea3f3e Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sun, 5 Jan 2020 11:33:40 +0900
Subject: include/ruby/ruby.h: remove last_idx that is no longer variable

Due to beae6cbf0fd8b6619e5212552de98022d4c4d4d4, the variable last_idx
is no longer changed and always -1.  This change simplifies the code by
removing the variable.  Coverity Scan pointed out this.

diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index d81c72e..56e293b 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -2517,7 +2517,7 @@ rb_scan_args_set(int argc, const VALUE *argv, https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2517
     __attribute__((diagnose_if(rb_scan_args_count(fmt)!=varc,"variable argument length doesn't match","error")))
 # endif
 {
-    int i, argi = 0, vari = 0, last_idx = -1;
+    int i, argi = 0, vari = 0;
     VALUE *var, hash = Qnil, last_hash = 0;
     const int n_mand = n_lead + n_trail;
     VALUE tmp_buffer = 0;
@@ -2534,14 +2534,14 @@ rb_scan_args_set(int argc, const VALUE *argv, https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2534
     /* capture leading mandatory arguments */
     for (i = n_lead; i-- > 0; ) {
 	var = vars[vari++];
-	if (var) *var = (argi == last_idx) ? last_hash : argv[argi];
+	if (var) *var = argv[argi];
 	argi++;
     }
     /* capture optional arguments */
     for (i = n_opt; i-- > 0; ) {
 	var = vars[vari++];
 	if (argi < argc - n_trail) {
-	    if (var) *var = (argi == last_idx) ? last_hash : argv[argi];
+	    if (var) *var = argv[argi];
 	    argi++;
 	}
 	else {
@@ -2555,7 +2555,7 @@ rb_scan_args_set(int argc, const VALUE *argv, https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2555
 	var = vars[vari++];
 	if (0 < n_var) {
 	    if (var) {
-		int f_last = (last_idx + 1 == argc - n_trail);
+		int f_last = (argc == n_trail);
 		*var = rb_ary_new4(n_var-f_last, &argv[argi]);
 		if (f_last) rb_ary_push(*var, last_hash);
 	    }
@@ -2568,7 +2568,7 @@ rb_scan_args_set(int argc, const VALUE *argv, https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2568
     /* capture trailing mandatory arguments */
     for (i = n_trail; i-- > 0; ) {
 	var = vars[vari++];
-	if (var) *var = (argi == last_idx) ? last_hash : argv[argi];
+	if (var) *var = argv[argi];
 	argi++;
     }
     /* capture an option hash - phase 2: assignment */
-- 
cgit v0.10.2


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

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