mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
id.def: predefine conversion method IDs
* defs/id.def: predefine conversion method name IDs. * object.c (conv_method_names): consitify with predefined IDs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a1305f14ec
commit
6a2ef9d6c3
2 changed files with 24 additions and 19 deletions
10
defs/id.def
10
defs/id.def
|
@ -26,6 +26,16 @@ firstline, predefined = __LINE__+1, %[\
|
||||||
initialize_copy
|
initialize_copy
|
||||||
initialize_clone
|
initialize_clone
|
||||||
initialize_dup
|
initialize_dup
|
||||||
|
to_int
|
||||||
|
to_ary
|
||||||
|
to_str
|
||||||
|
to_sym
|
||||||
|
to_hash
|
||||||
|
to_proc
|
||||||
|
to_io
|
||||||
|
to_a
|
||||||
|
to_s
|
||||||
|
|
||||||
_ UScore
|
_ UScore
|
||||||
"/*NULL*/" NULL
|
"/*NULL*/" NULL
|
||||||
empty?
|
empty?
|
||||||
|
|
33
object.c
33
object.c
|
@ -2545,20 +2545,21 @@ rb_mod_singleton_p(VALUE klass)
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct conv_method_tbl {
|
static const struct conv_method_tbl {
|
||||||
const char *method;
|
const char method[8];
|
||||||
ID id;
|
ID id;
|
||||||
} conv_method_names[] = {
|
} conv_method_names[] = {
|
||||||
{"to_int", 0},
|
#define M(n) {"to_"#n, idTo_##n}
|
||||||
{"to_ary", 0},
|
M(int),
|
||||||
{"to_str", 0},
|
M(ary),
|
||||||
{"to_sym", 0},
|
M(str),
|
||||||
{"to_hash", 0},
|
M(sym),
|
||||||
{"to_proc", 0},
|
M(hash),
|
||||||
{"to_io", 0},
|
M(proc),
|
||||||
{"to_a", 0},
|
M(io),
|
||||||
{"to_s", 0},
|
M(a),
|
||||||
{NULL, 0}
|
M(s),
|
||||||
|
#undef M
|
||||||
};
|
};
|
||||||
#define IMPLICIT_CONVERSIONS 7
|
#define IMPLICIT_CONVERSIONS 7
|
||||||
|
|
||||||
|
@ -2569,7 +2570,7 @@ convert_type(VALUE val, const char *tname, const char *method, int raise)
|
||||||
int i;
|
int i;
|
||||||
VALUE r;
|
VALUE r;
|
||||||
|
|
||||||
for (i=0; conv_method_names[i].method; i++) {
|
for (i=0; i < numberof(conv_method_names); i++) {
|
||||||
if (conv_method_names[i].method[0] == method[0] &&
|
if (conv_method_names[i].method[0] == method[0] &&
|
||||||
strcmp(conv_method_names[i].method, method) == 0) {
|
strcmp(conv_method_names[i].method, method) == 0) {
|
||||||
m = conv_method_names[i].id;
|
m = conv_method_names[i].id;
|
||||||
|
@ -3225,8 +3226,6 @@ rb_f_hash(VALUE obj, VALUE arg)
|
||||||
void
|
void
|
||||||
Init_Object(void)
|
Init_Object(void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
Init_class_hierarchy();
|
Init_class_hierarchy();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -3439,8 +3438,4 @@ Init_Object(void)
|
||||||
* An alias of +false+
|
* An alias of +false+
|
||||||
*/
|
*/
|
||||||
rb_define_global_const("FALSE", Qfalse);
|
rb_define_global_const("FALSE", Qfalse);
|
||||||
|
|
||||||
for (i=0; conv_method_names[i].method; i++) {
|
|
||||||
conv_method_names[i].id = rb_intern(conv_method_names[i].method);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue