summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-28 11:16:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-28 11:16:54 +0000
commit703a5dd3e0effdc808b9b59af21e5012f3d91942 (patch)
tree0ac6e156e2495468e2d9be0be22897203fd7e3e4 /range.c
parentd025f64a9f61683453a16a69a6dc65be321c657f (diff)
string.c: adjust to rb_str_upto_each
* range.c (range_each_func): adjust the signature of the callback function to rb_str_upto_each, and exit the loop if the callback returned non-zero. * string.c (rb_str_upto_endless_each): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c62
1 files changed, 26 insertions, 36 deletions
diff --git a/range.c b/range.c
index 88a35abc4e..7f59a97725 100644
--- a/range.c
+++ b/range.c
@@ -236,7 +236,7 @@ range_hash(VALUE range)
}
static void
-range_each_func(VALUE range, rb_block_call_func *func, VALUE arg)
+range_each_func(VALUE range, int (*func)(VALUE, VALUE), VALUE arg)
{
int c;
VALUE b = RANGE_BEG(range);
@@ -245,21 +245,21 @@ range_each_func(VALUE range, rb_block_call_func *func, VALUE arg)
if (EXCL(range)) {
while (r_less(v, e) < 0) {
- (*func) (v, arg, 0, 0, 0);
+ if ((*func)(v, arg)) break;
v = rb_funcallv(v, id_succ, 0, 0);
}
}
else {
while ((c = r_less(v, e)) <= 0) {
- (*func) (v, arg, 0, 0, 0);
+ if ((*func)(v, arg)) break;;
if (!c) break;
v = rb_funcallv(v, id_succ, 0, 0);
}
}
}
-static VALUE
-sym_step_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
+static int
+sym_step_i(VALUE i, VALUE arg)
{
VALUE *iter = (VALUE *)arg;
@@ -273,11 +273,11 @@ sym_step_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
rb_yield(rb_str_intern(i));
iter[0] = iter[1];
}
- return Qnil;
+ return 0;
}
-static VALUE
-step_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
+static int
+step_i(VALUE i, VALUE arg)
{
VALUE *iter = (VALUE *)arg;
@@ -291,7 +291,7 @@ step_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
rb_yield(i);
iter[0] = iter[1];
}
- return Qnil;
+ return 0;
}
static int
@@ -426,17 +426,16 @@ range_step(int argc, VALUE *argv, VALUE range)
}
else if (SYMBOL_P(b) && (NIL_P(e) || SYMBOL_P(e))) { /* symbols are special */
- VALUE args[2], iter[2];
+ VALUE iter[2];
iter[0] = INT2FIX(1);
iter[1] = step;
+ b = rb_sym2str(b);
if (NIL_P(e)) {
- rb_str_upto_endless_each(rb_sym2str(b), (VALUE (*)(VALUE, VALUE))sym_step_i, (VALUE)iter);
+ rb_str_upto_endless_each(b, sym_step_i, (VALUE)iter);
}
else {
- args[0] = rb_sym2str(e);
- args[1] = EXCL(range) ? Qtrue : Qfalse;
- rb_block_call(rb_sym2str(b), rb_intern("upto"), 2, args, sym_step_i, (VALUE)iter);
+ rb_str_upto_each(b, rb_sym2str(e), EXCL(range), sym_step_i, (VALUE)iter);
}
}
else if (ruby_float_step(b, e, step, EXCL(range), TRUE)) {
@@ -459,19 +458,17 @@ range_step(int argc, VALUE *argv, VALUE range)
tmp = rb_check_string_type(b);
if (!NIL_P(tmp)) {
- VALUE args[2], iter[2];
+ VALUE iter[2];
b = tmp;
iter[0] = INT2FIX(1);
iter[1] = step;
if (NIL_P(e)) {
- rb_str_upto_endless_each(b, (VALUE (*)(VALUE, VALUE))step_i, (VALUE)iter);
+ rb_str_upto_endless_each(b, step_i, (VALUE)iter);
}
else {
- args[0] = e;
- args[1] = EXCL(range) ? Qtrue : Qfalse;
- rb_block_call(b, rb_intern("upto"), 2, args, step_i, (VALUE)iter);
+ rb_str_upto_each(b, e, EXCL(range), step_i, (VALUE)iter);
}
}
else {
@@ -722,18 +719,18 @@ range_bsearch(VALUE range)
return range;
}
-static VALUE
-each_i(RB_BLOCK_CALL_FUNC_ARGLIST(v, arg))
+static int
+each_i(VALUE v, VALUE arg)
{
rb_yield(v);
- return Qnil;
+ return 0;
}
-static VALUE
-sym_each_i(RB_BLOCK_CALL_FUNC_ARGLIST(v, arg))
+static int
+sym_each_i(VALUE v, VALUE arg)
{
rb_yield(rb_str_intern(v));
- return Qnil;
+ return 0;
}
/*
@@ -817,25 +814,18 @@ range_each(VALUE range)
}
}
else if (SYMBOL_P(beg) && SYMBOL_P(end)) { /* symbols are special */
- VALUE args[2];
-
- args[0] = rb_sym2str(end);
- args[1] = EXCL(range) ? Qtrue : Qfalse;
- rb_block_call(rb_sym2str(beg), rb_intern("upto"), 2, args, sym_each_i, 0);
+ beg = rb_sym2str(beg);
+ rb_str_upto_each(beg, rb_sym2str(end), EXCL(range), sym_each_i, 0);
}
else {
VALUE tmp = rb_check_string_type(beg);
if (!NIL_P(tmp)) {
if (!NIL_P(end)) {
- VALUE args[2];
-
- args[0] = end;
- args[1] = EXCL(range) ? Qtrue : Qfalse;
- rb_block_call(tmp, rb_intern("upto"), 2, args, each_i, 0);
+ rb_str_upto_each(tmp, end, EXCL(range), each_i, 0);
}
else {
- rb_str_upto_endless_each(tmp, (VALUE (*)(VALUE, VALUE))each_i, 0);
+ rb_str_upto_endless_each(tmp, each_i, 0);
}
}
else {