ruby-changes:36111
From: nobu <ko1@a...>
Date: Thu, 30 Oct 2014 09:48:12 +0900 (JST)
Subject: [ruby-changes:36111] nobu:r48192 (trunk): ruby.h: optimize NUM2CHR
nobu 2014-10-30 09:47:58 +0900 (Thu, 30 Oct 2014) New Revision: 48192 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48192 Log: ruby.h: optimize NUM2CHR * include/ruby/ruby.h (rb_num2char_inline): use RB_TYPE_P for optimization. Modified files: trunk/include/ruby/ruby.h Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 48191) +++ include/ruby/ruby.h (revision 48192) @@ -488,6 +488,18 @@ enum ruby_value_type { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L488 static inline int rb_type(VALUE obj); #define TYPE(x) rb_type((VALUE)(x)) +#define RB_FLOAT_TYPE_P(obj) (FLONUM_P(obj) || (!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == T_FLOAT)) + +#define RB_TYPE_P(obj, type) ( \ + ((type) == T_FIXNUM) ? FIXNUM_P(obj) : \ + ((type) == T_TRUE) ? ((obj) == Qtrue) : \ + ((type) == T_FALSE) ? ((obj) == Qfalse) : \ + ((type) == T_NIL) ? ((obj) == Qnil) : \ + ((type) == T_UNDEF) ? ((obj) == Qundef) : \ + ((type) == T_SYMBOL) ? SYMBOL_P(obj) : \ + ((type) == T_FLOAT) ? RB_FLOAT_TYPE_P(obj) : \ + (!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == (type))) + /* RB_GC_GUARD_PTR() is an intermediate macro, and has no effect by * itself. don't use it directly */ #ifdef __GNUC__ @@ -1318,7 +1330,7 @@ rb_ulong2num_inline(unsigned long v) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1330 static inline char rb_num2char_inline(VALUE x) { - if ((TYPE(x) == T_STRING) && (RSTRING_LEN(x)>=1)) + if (RB_TYPE_P(x, T_STRING) && (RSTRING_LEN(x)>=1)) return RSTRING_PTR(x)[0]; else return (char)(NUM2INT(x) & 0xff); @@ -1661,18 +1673,6 @@ rb_type(VALUE obj) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1673 return BUILTIN_TYPE(obj); } -#define RB_FLOAT_TYPE_P(obj) (FLONUM_P(obj) || (!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == T_FLOAT)) - -#define RB_TYPE_P(obj, type) ( \ - ((type) == T_FIXNUM) ? FIXNUM_P(obj) : \ - ((type) == T_TRUE) ? ((obj) == Qtrue) : \ - ((type) == T_FALSE) ? ((obj) == Qfalse) : \ - ((type) == T_NIL) ? ((obj) == Qnil) : \ - ((type) == T_UNDEF) ? ((obj) == Qundef) : \ - ((type) == T_SYMBOL) ? SYMBOL_P(obj) : \ - ((type) == T_FLOAT) ? RB_FLOAT_TYPE_P(obj) : \ - (!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == (type))) - #ifdef __GNUC__ #define rb_type_p(obj, type) \ __extension__ (__builtin_constant_p(type) ? RB_TYPE_P((obj), (type)) : \ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/