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

* object.c (convert_type): call less rb_intern() less frequently

by using cache structure.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-08-28 11:50:31 +00:00
parent f7f0784270
commit 84b144f6de
2 changed files with 35 additions and 2 deletions

View file

@ -4,6 +4,9 @@ Thu Aug 28 20:22:49 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
behave like array. a patch from Yusuke Endoh <mame at tsg.ne.jp>
in [ruby-dev:35988]. [ruby-dev:35977]
* object.c (convert_type): call less rb_intern() less frequently
by using cache structure.
Thu Aug 28 19:04:50 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* bootstraptest/test_io.rb: no need to create real file.

View file

@ -1960,12 +1960,36 @@ rb_mod_cvar_defined(VALUE obj, VALUE iv)
return rb_cvar_defined(obj, id);
}
static struct conv_method_tbl {
const char *method;
ID id;
} conv_method_names[] = {
{"to_int", 0},
{"to_ary", 0},
{"to_str", 0},
{"to_sym", 0},
{"to_hash", 0},
{"to_proc", 0},
{"to_io", 0},
{"to_a", 0},
{"to_s", 0},
{NULL, 0}
};
static VALUE
convert_type(VALUE val, const char *tname, const char *method, int raise)
{
ID m;
ID m = 0;
int i;
m = rb_intern(method);
for (i=0; conv_method_names[i].method; i++) {
if (conv_method_names[i].method[0] == method[0] &&
strcmp(conv_method_names[i].method, method) == 0) {
m = conv_method_names[i].id;
break;
}
}
if (!m) m = rb_intern(method);
if (!rb_respond_to(val, m)) {
if (raise) {
rb_raise(rb_eTypeError, "can't convert %s into %s",
@ -2427,6 +2451,8 @@ boot_defclass(const char *name, VALUE super)
void
Init_Object(void)
{
int i;
#undef rb_intern
#define rb_intern(str) rb_intern_const(str)
@ -2606,4 +2632,8 @@ Init_Object(void)
id_match = rb_intern("=~");
id_inspect = rb_intern("inspect");
id_init_copy = rb_intern("initialize_copy");
for (i=0; conv_method_names[i].method; i++) {
conv_method_names[i].id = rb_intern(conv_method_names[i].method);
}
}