initialize IDs in advance.
* enumerator.c (Init_Enumerator): initialize IDs in advance. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
63e8110bfc
commit
b30aa26707
21
enumerator.c
21
enumerator.c
@ -105,7 +105,7 @@
|
|||||||
VALUE rb_cEnumerator;
|
VALUE rb_cEnumerator;
|
||||||
VALUE rb_cLazy;
|
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;
|
||||||
static ID id_eqq, id_next, id_result, id_lazy;
|
static ID id_eqq, id_next, id_result, id_lazy, id_receiver, id_arguments, id_method;
|
||||||
static VALUE sym_each, sym_cycle;
|
static VALUE sym_each, sym_cycle;
|
||||||
|
|
||||||
VALUE rb_eStopIteration;
|
VALUE rb_eStopIteration;
|
||||||
@ -875,7 +875,7 @@ inspect_enumerator(VALUE obj, VALUE dummy, int recur)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
eobj = rb_attr_get(obj, rb_intern("receiver"));
|
eobj = rb_attr_get(obj, id_receiver);
|
||||||
if (NIL_P(eobj)) {
|
if (NIL_P(eobj)) {
|
||||||
eobj = e->obj;
|
eobj = e->obj;
|
||||||
}
|
}
|
||||||
@ -886,7 +886,7 @@ inspect_enumerator(VALUE obj, VALUE dummy, int recur)
|
|||||||
/* (1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>" */
|
/* (1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>" */
|
||||||
str = rb_sprintf("#<%s: ", cname);
|
str = rb_sprintf("#<%s: ", cname);
|
||||||
rb_str_concat(str, rb_inspect(eobj));
|
rb_str_concat(str, rb_inspect(eobj));
|
||||||
method = rb_attr_get(obj, rb_intern("method"));
|
method = rb_attr_get(obj, id_method);
|
||||||
if (NIL_P(method)) {
|
if (NIL_P(method)) {
|
||||||
rb_str_buf_cat2(str, ":");
|
rb_str_buf_cat2(str, ":");
|
||||||
rb_str_buf_cat2(str, rb_id2name(e->meth));
|
rb_str_buf_cat2(str, rb_id2name(e->meth));
|
||||||
@ -897,7 +897,7 @@ inspect_enumerator(VALUE obj, VALUE dummy, int recur)
|
|||||||
rb_str_buf_cat2(str, rb_id2name(SYM2ID(method)));
|
rb_str_buf_cat2(str, rb_id2name(SYM2ID(method)));
|
||||||
}
|
}
|
||||||
|
|
||||||
eargs = rb_attr_get(obj, rb_intern("arguments"));
|
eargs = rb_attr_get(obj, id_arguments);
|
||||||
if (NIL_P(eargs)) {
|
if (NIL_P(eargs)) {
|
||||||
eargs = e->args;
|
eargs = e->args;
|
||||||
}
|
}
|
||||||
@ -1250,7 +1250,7 @@ lazy_initialize(int argc, VALUE *argv, VALUE self)
|
|||||||
(rb_block_given_p() ? lazy_init_block_i : lazy_init_block),
|
(rb_block_given_p() ? lazy_init_block_i : lazy_init_block),
|
||||||
obj);
|
obj);
|
||||||
enumerator_init(self, generator, meth, argc - offset, argv + offset);
|
enumerator_init(self, generator, meth, argc - offset, argv + offset);
|
||||||
rb_iv_set(self, "receiver", obj);
|
rb_ivar_set(self, id_receiver, obj);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -1259,13 +1259,13 @@ static VALUE
|
|||||||
lazy_set_method(VALUE lazy, VALUE args)
|
lazy_set_method(VALUE lazy, VALUE args)
|
||||||
{
|
{
|
||||||
ID id = rb_frame_this_func();
|
ID id = rb_frame_this_func();
|
||||||
rb_iv_set(lazy, "method", ID2SYM(id));
|
rb_ivar_set(lazy, id_method, ID2SYM(id));
|
||||||
if (NIL_P(args)) {
|
if (NIL_P(args)) {
|
||||||
/* Qfalse indicates that the arguments are empty */
|
/* Qfalse indicates that the arguments are empty */
|
||||||
rb_iv_set(lazy, "arguments", Qfalse);
|
rb_ivar_set(lazy, id_arguments, Qfalse);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_iv_set(lazy, "arguments", args);
|
rb_ivar_set(lazy, id_arguments, args);
|
||||||
}
|
}
|
||||||
return lazy;
|
return lazy;
|
||||||
}
|
}
|
||||||
@ -1308,7 +1308,7 @@ enumerable_lazy(VALUE obj)
|
|||||||
|
|
||||||
result = rb_class_new_instance(1, &obj, rb_cLazy);
|
result = rb_class_new_instance(1, &obj, rb_cLazy);
|
||||||
/* Qfalse indicates that the Enumerator::Lazy has no method name */
|
/* Qfalse indicates that the Enumerator::Lazy has no method name */
|
||||||
rb_iv_set(result, "method", Qfalse);
|
rb_ivar_set(result, id_method, Qfalse);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1801,6 +1801,9 @@ Init_Enumerator(void)
|
|||||||
id_result = rb_intern("result");
|
id_result = rb_intern("result");
|
||||||
id_lazy = rb_intern("lazy");
|
id_lazy = rb_intern("lazy");
|
||||||
id_eqq = rb_intern("===");
|
id_eqq = rb_intern("===");
|
||||||
|
id_receiver = rb_intern("receiver");
|
||||||
|
id_arguments = rb_intern("arguments");
|
||||||
|
id_method = rb_intern("method");
|
||||||
sym_each = ID2SYM(id_each);
|
sym_each = ID2SYM(id_each);
|
||||||
sym_cycle = ID2SYM(rb_intern("cycle"));
|
sym_cycle = ID2SYM(rb_intern("cycle"));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user