aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-26 08:57:45 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-26 08:57:45 +0000
commit7d368a369f59d59c0ffeb8e4ff2ccb1952c446e3 (patch)
tree50eab11f807f852240505bbf65d7dc7fb26e5a53 /object.c
parentd462e675f1db277c724b88df8dabb966b06fb0d8 (diff)
downloadruby-7d368a369f59d59c0ffeb8e4ff2ccb1952c446e3.tar.gz
object.c: common prefix of converter methods
* object.c (convert_type): check common prefix of converter method names first. shrink conv_method_names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/object.c b/object.c
index 685757987f..86468ca4e1 100644
--- a/object.c
+++ b/object.c
@@ -2557,10 +2557,10 @@ rb_mod_singleton_p(VALUE klass)
}
static const struct conv_method_tbl {
- const char method[8];
- ID id;
+ const char method[6];
+ unsigned short id;
} conv_method_names[] = {
-#define M(n) {"to_"#n, idTo_##n}
+#define M(n) {#n, (unsigned short)idTo_##n}
M(int),
M(ary),
M(str),
@@ -2581,12 +2581,16 @@ convert_type(VALUE val, const char *tname, const char *method, int raise)
ID m = 0;
int i;
VALUE r;
-
- for (i=0; i < numberof(conv_method_names); 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;
+ static const char prefix[] = "to_";
+
+ if (strncmp(prefix, method, sizeof(prefix)-1) == 0) {
+ const char *const meth = &method[sizeof(prefix)-1];
+ for (i=0; i < numberof(conv_method_names); i++) {
+ if (conv_method_names[i].method[0] == meth[0] &&
+ strcmp(conv_method_names[i].method, meth) == 0) {
+ m = conv_method_names[i].id;
+ break;
+ }
}
}
if (!m) m = rb_intern(method);