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

Init_Enumerator

* enumerator.c (Init_Enumerator): initialize method IDs first.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-03-14 01:35:09 +00:00
parent 48f9f0bda9
commit 8cdfe403d3
2 changed files with 10 additions and 7 deletions

View file

@ -103,7 +103,7 @@
*/
VALUE rb_cEnumerator;
VALUE rb_cLazy;
static ID id_rewind, id_each, id_new, id_initialize, id_yield, id_call;
static ID id_rewind, id_each, id_new, id_initialize, id_yield, id_call, id_next, id_result, id_lazy;
static VALUE sym_each;
VALUE rb_eStopIteration;
@ -563,7 +563,7 @@ next_i(VALUE curr, VALUE obj)
result = rb_block_call(obj, id_each, 0, 0, next_ii, obj);
e->stop_exc = rb_exc_new2(rb_eStopIteration, "iteration reached an end");
rb_ivar_set(e->stop_exc, rb_intern("result"), result);
rb_ivar_set(e->stop_exc, id_result, result);
return rb_fiber_yield(1, &nil);
}
@ -1403,7 +1403,7 @@ lazy_zip_func_i(VALUE val, VALUE arg, int argc, VALUE *argv)
ary = rb_ary_new2(RARRAY_LEN(arg) + 1);
rb_ary_push(ary, argv[1]);
for (i = 0; i < RARRAY_LEN(arg); i++) {
v = rb_funcall(RARRAY_PTR(arg)[i], rb_intern("next"), 0);
v = rb_funcall(RARRAY_PTR(arg)[i], id_next, 0);
rb_ary_push(ary, v);
}
result = rb_yield(ary);
@ -1421,7 +1421,7 @@ lazy_zip_func(VALUE val, VALUE arg, int argc, VALUE *argv)
ary = rb_ary_new2(RARRAY_LEN(arg) + 1);
rb_ary_push(ary, argv[1]);
for (i = 0; i < RARRAY_LEN(arg); i++) {
v = rb_funcall(RARRAY_PTR(arg)[i], rb_intern("next"), 0);
v = rb_funcall(RARRAY_PTR(arg)[i], id_next, 0);
rb_ary_push(ary, v);
}
rb_funcall(yielder, id_yield, 1, ary);
@ -1436,7 +1436,7 @@ lazy_zip(int argc, VALUE *argv, VALUE obj)
ary = rb_ary_new2(argc);
for (i = 0; i < argc; i++) {
rb_ary_push(ary, rb_funcall(argv[i], rb_intern("lazy"), 0));
rb_ary_push(ary, rb_funcall(argv[i], id_lazy, 0));
}
return rb_block_call(rb_cLazy, id_new, 1, &obj,
@ -1453,7 +1453,7 @@ lazy_lazy(VALUE obj)
static VALUE
stop_result(VALUE self)
{
return rb_attr_get(self, rb_intern("result"));
return rb_attr_get(self, id_result);
}
void
@ -1521,6 +1521,9 @@ Init_Enumerator(void)
id_yield = rb_intern("yield");
id_new = rb_intern("new");
id_initialize = rb_intern("initialize");
id_next = rb_intern("next");
id_result = rb_intern("result");
id_lazy = rb_intern("lazy");
sym_each = ID2SYM(id_each);
rb_provide("enumerator.so"); /* for backward compatibility */

View file

@ -127,7 +127,7 @@ class TestLazyEnumerator < Test::Unit::TestCase
assert_equal([1, "a"], a.lazy.zip("a".."c").first)
assert_equal(1, a.current)
end
def test_zip_without_arg
a = Step.new(1..3)
assert_equal([1], a.zip.first)