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

ruby-changes:68347

From: Nobuyoshi <ko1@a...>
Date: Sun, 10 Oct 2021 11:46:06 +0900 (JST)
Subject: [ruby-changes:68347] 2293547d9b (master): Update iteration step in step_i_iter

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

From 2293547d9b59e0641e26837500986e78f9ba891b Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 10 Oct 2021 11:41:26 +0900
Subject: Update iteration step in step_i_iter

---
 range.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/range.c b/range.c
index 96fcfe577b..cb86f540d8 100644
--- a/range.c
+++ b/range.c
@@ -308,7 +308,7 @@ range_each_func(VALUE range, int (*func)(VALUE, VALUE), VALUE arg) https://github.com/ruby/ruby/blob/trunk/range.c#L308
     }
 }
 
-static VALUE*
+static bool
 step_i_iter(VALUE arg)
 {
     VALUE *iter = (VALUE *)arg;
@@ -319,17 +319,16 @@ step_i_iter(VALUE arg) https://github.com/ruby/ruby/blob/trunk/range.c#L319
     else {
 	iter[0] = rb_funcall(iter[0], '-', 1, INT2FIX(1));
     }
-    return iter;
+    if (iter[0] != INT2FIX(0)) return false;
+    iter[0] = iter[1];
+    return true;
 }
 
 static int
 sym_step_i(VALUE i, VALUE arg)
 {
-    VALUE *iter = step_i_iter(arg);
-
-    if (iter[0] == INT2FIX(0)) {
+    if (step_i_iter(arg)) {
 	rb_yield(rb_str_intern(i));
-	iter[0] = iter[1];
     }
     return 0;
 }
@@ -337,11 +336,8 @@ sym_step_i(VALUE i, VALUE arg) https://github.com/ruby/ruby/blob/trunk/range.c#L336
 static int
 step_i(VALUE i, VALUE arg)
 {
-    VALUE *iter = step_i_iter(arg);
-
-    if (iter[0] == INT2FIX(0)) {
+    if (step_i_iter(arg)) {
 	rb_yield(i);
-	iter[0] = iter[1];
     }
     return 0;
 }
-- 
cgit v1.2.1


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

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