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

ruby-changes:33945

From: nobu <ko1@a...>
Date: Tue, 20 May 2014 15:29:07 +0900 (JST)
Subject: [ruby-changes:33945] nobu:r46026 (trunk): id.def: predefine conversion method IDs

nobu	2014-05-20 15:28:52 +0900 (Tue, 20 May 2014)

  New Revision: 46026

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

  Log:
    id.def: predefine conversion method IDs
    
    * defs/id.def: predefine conversion method name IDs.
    
    * object.c (conv_method_names): consitify with predefined IDs.

  Modified files:
    trunk/defs/id.def
    trunk/object.c
Index: defs/id.def
===================================================================
--- defs/id.def	(revision 46025)
+++ defs/id.def	(revision 46026)
@@ -26,6 +26,16 @@ firstline, predefined = __LINE__+1, %[\ https://github.com/ruby/ruby/blob/trunk/defs/id.def#L26
   initialize_copy
   initialize_clone
   initialize_dup
+  to_int
+  to_ary
+  to_str
+  to_sym
+  to_hash
+  to_proc
+  to_io
+  to_a
+  to_s
+
   _                                                     UScore
   "/*NULL*/"                                            NULL
   empty?
Index: object.c
===================================================================
--- object.c	(revision 46025)
+++ object.c	(revision 46026)
@@ -2545,20 +2545,21 @@ rb_mod_singleton_p(VALUE klass) https://github.com/ruby/ruby/blob/trunk/object.c#L2545
     return Qfalse;
 }
 
-static struct conv_method_tbl {
-    const char *method;
+static const struct conv_method_tbl {
+    const char method[8];
     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}
+#define M(n) {"to_"#n, idTo_##n}
+    M(int),
+    M(ary),
+    M(str),
+    M(sym),
+    M(hash),
+    M(proc),
+    M(io),
+    M(a),
+    M(s),
+#undef M
 };
 #define IMPLICIT_CONVERSIONS 7
 
@@ -2569,7 +2570,7 @@ convert_type(VALUE val, const char *tnam https://github.com/ruby/ruby/blob/trunk/object.c#L2570
     int i;
     VALUE r;
 
-    for (i=0; conv_method_names[i].method; i++) {
+    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;
@@ -3225,8 +3226,6 @@ rb_f_hash(VALUE obj, VALUE arg) https://github.com/ruby/ruby/blob/trunk/object.c#L3226
 void
 Init_Object(void)
 {
-    int i;
-
     Init_class_hierarchy();
 
 #if 0
@@ -3439,8 +3438,4 @@ Init_Object(void) https://github.com/ruby/ruby/blob/trunk/object.c#L3438
      * An alias of +false+
      */
     rb_define_global_const("FALSE", Qfalse);
-
-    for (i=0; conv_method_names[i].method; i++) {
-	conv_method_names[i].id = rb_intern(conv_method_names[i].method);
-    }
 }

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

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