summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-30 00:47:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-30 00:47:58 +0000
commit44d2958e3b6ba71de033b7f84960c3283558f755 (patch)
tree8e8a51198a4c5858031f4e7e25ca27ac99e838ef /include
parent19121b47392732c5083e36478a24d7883efab299 (diff)
ruby.h: optimize NUM2CHR
* include/ruby/ruby.h (rb_num2char_inline): use RB_TYPE_P for optimization. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r--include/ruby/ruby.h26
1 files changed, 13 insertions, 13 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 8b133cd7cc..2b175fd89e 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -488,6 +488,18 @@ enum ruby_value_type {
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)
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)
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)) : \