ruby-changes:68346
From: S.H <ko1@a...>
Date: Sun, 10 Oct 2021 11:40:16 +0900 (JST)
Subject: [ruby-changes:68346] afb95d1004 (master): Refactor sym_step_i function
https://git.ruby-lang.org/ruby.git/commit/?id=afb95d1004 From afb95d1004676f71beb0dab389b19695728726e5 Mon Sep 17 00:00:00 2001 From: "S.H" <gamelinks007@g...> Date: Sun, 10 Oct 2021 11:40:04 +0900 Subject: Refactor sym_step_i function --- range.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/range.c b/range.c index 31f734181d..96fcfe577b 100644 --- a/range.c +++ b/range.c @@ -308,8 +308,8 @@ range_each_func(VALUE range, int (*func)(VALUE, VALUE), VALUE arg) https://github.com/ruby/ruby/blob/trunk/range.c#L308 } } -static int -sym_step_i(VALUE i, VALUE arg) +static VALUE* +step_i_iter(VALUE arg) { VALUE *iter = (VALUE *)arg; @@ -319,6 +319,14 @@ sym_step_i(VALUE i, VALUE arg) https://github.com/ruby/ruby/blob/trunk/range.c#L319 else { iter[0] = rb_funcall(iter[0], '-', 1, INT2FIX(1)); } + return iter; +} + +static int +sym_step_i(VALUE i, VALUE arg) +{ + VALUE *iter = step_i_iter(arg); + if (iter[0] == INT2FIX(0)) { rb_yield(rb_str_intern(i)); iter[0] = iter[1]; @@ -329,14 +337,8 @@ sym_step_i(VALUE i, VALUE arg) https://github.com/ruby/ruby/blob/trunk/range.c#L337 static int step_i(VALUE i, VALUE arg) { - VALUE *iter = (VALUE *)arg; + VALUE *iter = step_i_iter(arg); - if (FIXNUM_P(iter[0])) { - iter[0] -= INT2FIX(1) & ~FIXNUM_FLAG; - } - else { - iter[0] = rb_funcall(iter[0], '-', 1, INT2FIX(1)); - } if (iter[0] == INT2FIX(0)) { rb_yield(i); iter[0] = iter[1]; -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/