diff options
author | S.H <gamelinks007@gmail.com> | 2021-10-10 11:40:04 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-10 11:40:04 +0900 |
commit | afb95d1004676f71beb0dab389b19695728726e5 (patch) | |
tree | 301c00e7919cf4aaa17f5a816807b41911a47dc1 /range.c | |
parent | f6048e592c520e20ba498ba4d553f07f02213a61 (diff) |
Refactor sym_step_i function
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4923
Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'range.c')
-rw-r--r-- | range.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -308,8 +308,8 @@ range_each_func(VALUE range, int (*func)(VALUE, VALUE), VALUE arg) } } -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) 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) 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]; |