ruby-changes:24390
From: nobu <ko1@a...>
Date: Wed, 18 Jul 2012 17:45:40 +0900 (JST)
Subject: [ruby-changes:24390] nobu:r36441 (trunk): error.c: map by index
nobu 2012-07-18 17:45:29 +0900 (Wed, 18 Jul 2012) New Revision: 36441 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36441 Log: error.c: map by index * error.c (rb_builtin_type_name): map by index. Modified files: trunk/ChangeLog trunk/error.c Index: ChangeLog =================================================================== --- ChangeLog (revision 36440) +++ ChangeLog (revision 36441) @@ -1,3 +1,7 @@ +Wed Jul 18 17:45:26 2012 Nobuyoshi Nakada <nobu@r...> + + * error.c (rb_builtin_type_name): map by index. + Wed Jul 18 16:17:40 2012 Nobuyoshi Nakada <nobu@r...> * lib/mkmf.rb (have_framework): get rid of separating -framework Index: error.c =================================================================== --- error.c (revision 36440) +++ error.c (revision 36441) @@ -25,6 +25,8 @@ #include <unistd.h> #endif +#define numberof(array) (int)(sizeof(array) / sizeof((array)[0])) + #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif @@ -387,45 +389,46 @@ abort(); } -static const struct types { - int type; - const char *name; -} builtin_types[] = { - {T_NIL, "nil"}, - {T_OBJECT, "Object"}, - {T_CLASS, "Class"}, - {T_ICLASS, "iClass"}, /* internal use: mixed-in module holder */ - {T_MODULE, "Module"}, - {T_FLOAT, "Float"}, - {T_STRING, "String"}, - {T_REGEXP, "Regexp"}, - {T_ARRAY, "Array"}, - {T_FIXNUM, "Fixnum"}, - {T_HASH, "Hash"}, - {T_STRUCT, "Struct"}, - {T_BIGNUM, "Bignum"}, - {T_FILE, "File"}, - {T_RATIONAL,"Rational"}, - {T_COMPLEX, "Complex"}, - {T_TRUE, "true"}, - {T_FALSE, "false"}, - {T_SYMBOL, "Symbol"}, /* :symbol */ - {T_DATA, "Data"}, /* internal use: wrapped C pointers */ - {T_MATCH, "MatchData"}, /* data of $~ */ - {T_NODE, "Node"}, /* internal use: syntax tree node */ - {T_UNDEF, "undef"}, /* internal use: #undef; should not happen */ +static const char builtin_types[][10] = { + "", /* 0x00, */ + "Object", + "Class", + "Module", + "Float", + "String", + "Regexp", + "Array", + "Hash", + "Struct", + "Bignum", + "File", + "Data", /* internal use: wrapped C pointers */ + "MatchData", /* data of $~ */ + "Complex", + "Rational", + "", /* 0x10 */ + "nil", + "true", + "false", + "Symbol", /* :symbol */ + "Fixnum", + "", /* 0x16 */ + "", /* 0x17 */ + "", /* 0x18 */ + "", /* 0x19 */ + {}, /* 0x1a */ + "undef", /* internal use: #undef; should not happen */ + "Node", /* internal use: syntax tree node */ + "iClass", /* internal use: mixed-in module holder */ }; const char * rb_builtin_type_name(int t) { - const struct types *type = builtin_types; - const struct types *const typeend = builtin_types + - sizeof(builtin_types) / sizeof(builtin_types[0]); - while (type < typeend) { - if (type->type == t) return type->name; - type++; - } + const char *name; + if ((unsigned int)t > numberof(builtin_types)) return 0; + name = builtin_types[t]; + if (*name) return name; return 0; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/