summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-28 11:50:31 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-28 11:50:31 +0000
commit84b144f6de2cb5eccb9b534217f3cf943896b613 (patch)
treeabc102f2bdadb9196356d8b3dcebe939100f3b54 /object.c
parentf7f0784270ce51fac9c21b58668b3e455d2ae60e (diff)
* 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
Diffstat (limited to 'object.c')
-rw-r--r--object.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/object.c b/object.c
index 3c95ef9515..b796cfbf3c 100644
--- a/object.c
+++ b/object.c
@@ -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);
+ }
}