summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--object.c34
2 files changed, 35 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 1c35787ac9..8c028f81e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
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);
+ }
}