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).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-05-18 01:17:43 +00:00
parent abe32a00b1
commit 4a9705d6e3
8 changed files with 25 additions and 11 deletions

View File

@ -1,3 +1,9 @@
Wed May 18 10:17:41 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@mrkn.jp>
* enum.c (enum_sum, hash_sum, hash_sum_i, enum_sum_i, sum_iter):

View File

@ -110,7 +110,7 @@ f_mul(VALUE x, VALUE y)
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)
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)

View File

@ -1360,7 +1360,7 @@ encode_year(VALUE nth, int y, double style,
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)
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);
}

View File

@ -1504,6 +1504,15 @@ rb_obj_write(VALUE a, VALUE *slot, VALUE b, RB_UNUSED_VAR(const char *filename),
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))

View File

@ -4037,11 +4037,10 @@ int_comp(VALUE num)
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);
}
}

View File

@ -106,7 +106,7 @@ f_mul(VALUE x, VALUE y)
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)
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)

View File

@ -1043,7 +1043,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
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;
}

View File

@ -2746,7 +2746,7 @@ rb_str_concat(VALUE str1, VALUE str2)
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)) {