mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enumerator.c (get_next_values): extracted from
enumerator_next_values. (enumerator_next_values): use get_next_values. (enumerator_peek_values): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a7b920686a
commit
3a855da47b
2 changed files with 39 additions and 29 deletions
|
@ -1,3 +1,10 @@
|
|||
Fri Aug 21 22:34:58 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* enumerator.c (get_next_values): extracted from
|
||||
enumerator_next_values.
|
||||
(enumerator_next_values): use get_next_values.
|
||||
(enumerator_peek_values): ditto.
|
||||
|
||||
Fri Aug 21 17:01:04 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* enc/unicode/name2ctype.h: split from enc/unicode.c and made a
|
||||
|
|
61
enumerator.c
61
enumerator.c
|
@ -594,6 +594,31 @@ next_init(VALUE obj, struct enumerator *e)
|
|||
e->lookahead = Qundef;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
get_next_values(VALUE obj, struct enumerator *e)
|
||||
{
|
||||
VALUE curr, vs;
|
||||
|
||||
if (e->stop_exc)
|
||||
rb_exc_raise(e->stop_exc);
|
||||
|
||||
curr = rb_fiber_current();
|
||||
|
||||
if (!e->fib || !rb_fiber_alive_p(e->fib)) {
|
||||
next_init(obj, e);
|
||||
}
|
||||
|
||||
vs = rb_fiber_resume(e->fib, 1, &curr);
|
||||
if (e->stop_exc) {
|
||||
e->fib = 0;
|
||||
e->dst = Qnil;
|
||||
e->lookahead = Qundef;
|
||||
e->feedvalue = Qundef;
|
||||
rb_exc_raise(e->stop_exc);
|
||||
}
|
||||
return vs;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* e.next_values => array
|
||||
|
@ -642,32 +667,15 @@ static VALUE
|
|||
enumerator_next_values(VALUE obj)
|
||||
{
|
||||
struct enumerator *e = enumerator_ptr(obj);
|
||||
VALUE curr, v;
|
||||
VALUE vs;
|
||||
|
||||
if (e->lookahead != Qundef) {
|
||||
v = e->lookahead;
|
||||
vs = e->lookahead;
|
||||
e->lookahead = Qundef;
|
||||
return v;
|
||||
return vs;
|
||||
}
|
||||
|
||||
if (e->stop_exc)
|
||||
rb_exc_raise(e->stop_exc);
|
||||
|
||||
curr = rb_fiber_current();
|
||||
|
||||
if (!e->fib || !rb_fiber_alive_p(e->fib)) {
|
||||
next_init(obj, e);
|
||||
}
|
||||
|
||||
v = rb_fiber_resume(e->fib, 1, &curr);
|
||||
if (e->stop_exc) {
|
||||
e->fib = 0;
|
||||
e->dst = Qnil;
|
||||
e->lookahead = Qundef;
|
||||
e->feedvalue = Qundef;
|
||||
rb_exc_raise(e->stop_exc);
|
||||
}
|
||||
return v;
|
||||
return get_next_values(obj, e);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -738,16 +746,11 @@ static VALUE
|
|||
enumerator_peek_values(VALUE obj)
|
||||
{
|
||||
struct enumerator *e = enumerator_ptr(obj);
|
||||
VALUE v;
|
||||
|
||||
if (e->lookahead != Qundef) {
|
||||
v = e->lookahead;
|
||||
return v;
|
||||
if (e->lookahead == Qundef) {
|
||||
e->lookahead = get_next_values(obj, e);
|
||||
}
|
||||
|
||||
v = enumerator_next_values(obj);
|
||||
e->lookahead = v;
|
||||
return v;
|
||||
return e->lookahead;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue