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

* enumerator.c (enumerator_block_call): extracted.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-09-29 15:37:28 +00:00
parent 5b2d54be66
commit 40e50764f4
2 changed files with 26 additions and 36 deletions

View file

@ -1,3 +1,7 @@
Wed Sep 30 00:37:27 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* enumerator.c (enumerator_block_call): extracted.
Wed Sep 30 00:00:25 2009 NARUSE, Yui <naruse@ruby-lang.org> Wed Sep 30 00:00:25 2009 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (rb_str_inspect): escape as \x{XXXX} when the encoding is * string.c (rb_str_inspect): escape as \x{XXXX} when the encoding is

View file

@ -400,7 +400,8 @@ enumerator_initialize(int argc, VALUE *argv, VALUE obj)
rb_raise(rb_eArgError, "wrong number of argument (0 for 1+)"); rb_raise(rb_eArgError, "wrong number of argument (0 for 1+)");
recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc()); recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
} else { }
else {
recv = *argv++; recv = *argv++;
if (--argc) { if (--argc) {
meth = *argv++; meth = *argv++;
@ -445,6 +446,21 @@ rb_enumeratorize(VALUE obj, VALUE meth, int argc, VALUE *argv)
return enumerator_init(enumerator_allocate(rb_cEnumerator), obj, meth, argc, argv); return enumerator_init(enumerator_allocate(rb_cEnumerator), obj, meth, argc, argv);
} }
static VALUE
enumerator_block_call(VALUE obj, rb_block_call_func *func, VALUE arg)
{
int argc = 0;
VALUE *argv = 0;
const struct enumerator *e = enumerator_ptr(obj);
ID meth = e->meth;
if (e->args) {
argc = RARRAY_LENINT(e->args);
argv = RARRAY_PTR(e->args);
}
return rb_block_call(e->obj, meth, argc, argv, func, arg);
}
/* /*
* call-seq: * call-seq:
* enum.each {...} * enum.each {...}
@ -456,24 +472,15 @@ rb_enumeratorize(VALUE obj, VALUE meth, int argc, VALUE *argv)
static VALUE static VALUE
enumerator_each(VALUE obj) enumerator_each(VALUE obj)
{ {
struct enumerator *e;
int argc = 0;
VALUE *argv = 0;
if (!rb_block_given_p()) return obj; if (!rb_block_given_p()) return obj;
e = enumerator_ptr(obj); return enumerator_block_call(obj, enumerator_each_i, obj);
if (e->args) {
argc = RARRAY_LENINT(e->args);
argv = RARRAY_PTR(e->args);
}
return rb_block_call(e->obj, e->meth, argc, argv,
enumerator_each_i, (VALUE)e);
} }
static VALUE static VALUE
enumerator_with_index_i(VALUE val, VALUE *memo, int argc, VALUE *argv) enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv)
{ {
VALUE idx; VALUE idx;
VALUE *memo = (VALUE *)m;
idx = INT2FIX(*memo); idx = INT2FIX(*memo);
++*memo; ++*memo;
@ -496,23 +503,12 @@ enumerator_with_index_i(VALUE val, VALUE *memo, int argc, VALUE *argv)
static VALUE static VALUE
enumerator_with_index(int argc, VALUE *argv, VALUE obj) enumerator_with_index(int argc, VALUE *argv, VALUE obj)
{ {
struct enumerator *e;
VALUE memo; VALUE memo;
rb_scan_args(argc, argv, "01", &memo); rb_scan_args(argc, argv, "01", &memo);
RETURN_ENUMERATOR(obj, argc, argv); RETURN_ENUMERATOR(obj, argc, argv);
memo = NIL_P(memo) ? 0 : (VALUE)NUM2LONG(memo); memo = NIL_P(memo) ? 0 : (VALUE)NUM2LONG(memo);
e = enumerator_ptr(obj); return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo);
if (e->args) {
argc = RARRAY_LENINT(e->args);
argv = RARRAY_PTR(e->args);
}
else {
argc = 0;
argv = NULL;
}
return rb_block_call(e->obj, e->meth, argc, argv,
enumerator_with_index_i, (VALUE)&memo);
} }
/* /*
@ -553,18 +549,8 @@ enumerator_with_object_i(VALUE val, VALUE memo, int argc, VALUE *argv)
static VALUE static VALUE
enumerator_with_object(VALUE obj, VALUE memo) enumerator_with_object(VALUE obj, VALUE memo)
{ {
struct enumerator *e;
int argc = 0;
VALUE *argv = 0;
RETURN_ENUMERATOR(obj, 1, &memo); RETURN_ENUMERATOR(obj, 1, &memo);
e = enumerator_ptr(obj); enumerator_block_call(obj, enumerator_with_object_i, memo);
if (e->args) {
argc = RARRAY_LENINT(e->args);
argv = RARRAY_PTR(e->args);
}
rb_block_call(e->obj, e->meth, argc, argv,
enumerator_with_object_i, memo);
return memo; return memo;
} }