diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-21 13:39:35 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-21 13:39:35 +0000 |
commit | 3a855da47b867e24428582b0a20aa1ea7e4dc2af (patch) | |
tree | 9735c7cd9a0a92ddb65f85983684ccf9f64bb33c /enumerator.c | |
parent | a7b920686af51c7f54a2b1bd9e53c657db41d360 (diff) | |
download | ruby-3a855da47b867e24428582b0a20aa1ea7e4dc2af.tar.gz |
* 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
Diffstat (limited to 'enumerator.c')
-rw-r--r-- | enumerator.c | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/enumerator.c b/enumerator.c index 2feb24ca20..ce4a4ee3df 100644 --- a/enumerator.c +++ b/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; } /* |