1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Unify iteration arguments

This commit is contained in:
Nobuyoshi Nakada 2021-10-10 11:45:50 +09:00
parent 2293547d9b
commit e2017f8c7c
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

16
range.c
View file

@ -463,6 +463,7 @@ range_step(int argc, VALUE *argv, VALUE range)
} }
step = check_step_domain(step); step = check_step_domain(step);
VALUE iter[2] = {INT2FIX(1), step};
if (FIXNUM_P(b) && NIL_P(e) && FIXNUM_P(step)) { if (FIXNUM_P(b) && NIL_P(e) && FIXNUM_P(step)) {
long i = FIX2LONG(b), unit = FIX2LONG(step); long i = FIX2LONG(b), unit = FIX2LONG(step);
@ -490,10 +491,6 @@ range_step(int argc, VALUE *argv, VALUE range)
} }
else if (SYMBOL_P(b) && (NIL_P(e) || SYMBOL_P(e))) { /* symbols are special */ else if (SYMBOL_P(b) && (NIL_P(e) || SYMBOL_P(e))) { /* symbols are special */
VALUE iter[2];
iter[0] = INT2FIX(1);
iter[1] = step;
b = rb_sym2str(b); b = rb_sym2str(b);
if (NIL_P(e)) { if (NIL_P(e)) {
rb_str_upto_endless_each(b, sym_step_i, (VALUE)iter); rb_str_upto_endless_each(b, sym_step_i, (VALUE)iter);
@ -522,12 +519,7 @@ range_step(int argc, VALUE *argv, VALUE range)
tmp = rb_check_string_type(b); tmp = rb_check_string_type(b);
if (!NIL_P(tmp)) { if (!NIL_P(tmp)) {
VALUE iter[2];
b = tmp; b = tmp;
iter[0] = INT2FIX(1);
iter[1] = step;
if (NIL_P(e)) { if (NIL_P(e)) {
rb_str_upto_endless_each(b, step_i, (VALUE)iter); rb_str_upto_endless_each(b, step_i, (VALUE)iter);
} }
@ -536,15 +528,11 @@ range_step(int argc, VALUE *argv, VALUE range)
} }
} }
else { else {
VALUE args[2];
if (!discrete_object_p(b)) { if (!discrete_object_p(b)) {
rb_raise(rb_eTypeError, "can't iterate from %s", rb_raise(rb_eTypeError, "can't iterate from %s",
rb_obj_classname(b)); rb_obj_classname(b));
} }
args[0] = INT2FIX(1); range_each_func(range, step_i, (VALUE)iter);
args[1] = step;
range_each_func(range, step_i, (VALUE)args);
} }
} }
return range; return range;