ruby-changes:42970
From: nobu <ko1@a...>
Date: Wed, 18 May 2016 10:17:47 +0900 (JST)
Subject: [ruby-changes:42970] nobu:r55044 (trunk): ruby.h: RB_INTEGER_TYPE_P
nobu 2016-05-18 10:17:43 +0900 (Wed, 18 May 2016) New Revision: 55044 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55044 Log: ruby.h: RB_INTEGER_TYPE_P * include/ruby/ruby.h (RB_INTEGER_TYPE_P): new macro and underlying inline function to check if the object is an Integer (Fixnum or Bignum). Modified files: trunk/ChangeLog trunk/complex.c trunk/ext/date/date_core.c trunk/include/ruby/ruby.h trunk/numeric.c trunk/rational.c trunk/sprintf.c trunk/string.c Index: complex.c =================================================================== --- complex.c (revision 55043) +++ complex.c (revision 55044) @@ -110,7 +110,7 @@ f_mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/complex.c#L110 if (FIXNUM_P(y)) { long iy = FIX2LONG(y); if (iy == 0) { - if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM)) + if (RB_INTEGER_TYPE_P(x)) return ZERO; } else if (iy == 1) @@ -119,7 +119,7 @@ f_mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/complex.c#L119 else if (FIXNUM_P(x)) { long ix = FIX2LONG(x); if (ix == 0) { - if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM)) + if (RB_INTEGER_TYPE_P(y)) return ZERO; } else if (ix == 1) Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 55043) +++ include/ruby/ruby.h (revision 55044) @@ -1504,6 +1504,15 @@ rb_obj_write(VALUE a, VALUE *slot, VALUE https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1504 return a; } +#define RB_INTEGER_TYPE_P(obj) rb_integer_type_p(obj) +static inline int +rb_integer_type_p(VALUE obj) +{ + return (RB_FIXNUM_P(obj) || + (!RB_SPECIAL_CONST_P(obj) && + RB_BUILTIN_TYPE(obj) == RUBY_T_BIGNUM)); +} + #if SIZEOF_INT < SIZEOF_LONG # define RB_INT2NUM(v) INT2FIX((int)(v)) # define RB_UINT2NUM(v) LONG2FIX((unsigned int)(v)) Index: ChangeLog =================================================================== --- ChangeLog (revision 55043) +++ ChangeLog (revision 55044) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed May 18 10:17:41 2016 Nobuyoshi Nakada <nobu@r...> + + * include/ruby/ruby.h (RB_INTEGER_TYPE_P): new macro and + underlying inline function to check if the object is an + Integer (Fixnum or Bignum). + Wed May 18 09:52:00 2016 Kenta Murata <mrkn@m...> * enum.c (enum_sum, hash_sum, hash_sum_i, enum_sum_i, sum_iter): Index: rational.c =================================================================== --- rational.c (revision 55043) +++ rational.c (revision 55044) @@ -106,7 +106,7 @@ f_mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/rational.c#L106 if (FIXNUM_P(y)) { long iy = FIX2LONG(y); if (iy == 0) { - if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM)) + if (RB_INTEGER_TYPE_P(x)) return ZERO; } else if (iy == 1) @@ -115,7 +115,7 @@ f_mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/rational.c#L115 else if (FIXNUM_P(x)) { long ix = FIX2LONG(x); if (ix == 0) { - if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM)) + if (RB_INTEGER_TYPE_P(y)) return ZERO; } else if (ix == 1) Index: sprintf.c =================================================================== --- sprintf.c (revision 55043) +++ sprintf.c (revision 55044) @@ -1043,7 +1043,7 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/sprintf.c#L1043 VALUE val = GETARG(), num, den; int sign = (flags&FPLUS) ? 1 : 0, zero = 0; long len, fill; - if (FIXNUM_P(val) || RB_TYPE_P(val, T_BIGNUM)) { + if (RB_INTEGER_TYPE_P(val)) { den = INT2FIX(1); num = val; } Index: ext/date/date_core.c =================================================================== --- ext/date/date_core.c (revision 55043) +++ ext/date/date_core.c (revision 55044) @@ -1360,7 +1360,7 @@ encode_year(VALUE nth, int y, double sty https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L1360 static void decode_jd(VALUE jd, VALUE *nth, int *rjd) { - assert(FIXNUM_P(jd) || RB_TYPE_P(jd, T_BIGNUM)); + assert(RB_INTEGER_TYPE_P(jd)); *nth = f_idiv(jd, INT2FIX(CM_PERIOD)); if (f_zero_p(*nth)) { assert(FIXNUM_P(jd)); @@ -3133,7 +3133,7 @@ wholenum_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L3133 inline static VALUE to_integer(VALUE x) { - if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM)) + if (RB_INTEGER_TYPE_P(x)) return x; return f_to_i(x); } Index: numeric.c =================================================================== --- numeric.c (revision 55043) +++ numeric.c (revision 55044) @@ -4037,11 +4037,10 @@ int_comp(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4037 static int bit_coerce(VALUE *x, VALUE *y) { - if (!FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) { + if (!RB_INTEGER_TYPE_P(*y)) { VALUE orig = *x; do_coerce(x, y, TRUE); - if (!FIXNUM_P(*x) && !RB_TYPE_P(*x, T_BIGNUM) - && !FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) { + if (!RB_INTEGER_TYPE_P(*x) && !RB_INTEGER_TYPE_P(*y)) { coerce_failed(orig, *y); } } Index: string.c =================================================================== --- string.c (revision 55043) +++ string.c (revision 55044) @@ -2746,7 +2746,7 @@ rb_str_concat(VALUE str1, VALUE str2) https://github.com/ruby/ruby/blob/trunk/string.c#L2746 rb_encoding *enc = STR_ENC_GET(str1); int encidx; - if (FIXNUM_P(str2) || RB_TYPE_P(str2, T_BIGNUM)) { + if (RB_INTEGER_TYPE_P(str2)) { if (rb_num_to_uint(str2, &code) == 0) { } else if (FIXNUM_P(str2)) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/