[前][次][番号順一覧][スレッド一覧]

ruby-changes:38958

From: nobu <ko1@a...>
Date: Fri, 26 Jun 2015 17:58:03 +0900 (JST)
Subject: [ruby-changes:38958] nobu:r51039 (trunk): object.c: common prefix of converter methods

nobu	2015-06-26 17:57:45 +0900 (Fri, 26 Jun 2015)

  New Revision: 51039

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51039

  Log:
    object.c: common prefix of converter methods
    
    * object.c (convert_type): check common prefix of converter
      method names first.  shrink conv_method_names.

  Modified files:
    trunk/object.c
Index: object.c
===================================================================
--- object.c	(revision 51038)
+++ object.c	(revision 51039)
@@ -2557,10 +2557,10 @@ rb_mod_singleton_p(VALUE klass) https://github.com/ruby/ruby/blob/trunk/object.c#L2557
 }
 
 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 *tnam https://github.com/ruby/ruby/blob/trunk/object.c#L2581
     ID m = 0;
     int i;
     VALUE r;
+    static const char prefix[] = "to_";
 
-    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;
+    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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]