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:
parent
abe32a00b1
commit
4a9705d6e3
@ -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>
|
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):
|
* enum.c (enum_sum, hash_sum, hash_sum_i, enum_sum_i, sum_iter):
|
||||||
|
@ -110,7 +110,7 @@ f_mul(VALUE x, VALUE y)
|
|||||||
if (FIXNUM_P(y)) {
|
if (FIXNUM_P(y)) {
|
||||||
long iy = FIX2LONG(y);
|
long iy = FIX2LONG(y);
|
||||||
if (iy == 0) {
|
if (iy == 0) {
|
||||||
if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM))
|
if (RB_INTEGER_TYPE_P(x))
|
||||||
return ZERO;
|
return ZERO;
|
||||||
}
|
}
|
||||||
else if (iy == 1)
|
else if (iy == 1)
|
||||||
@ -119,7 +119,7 @@ f_mul(VALUE x, VALUE y)
|
|||||||
else if (FIXNUM_P(x)) {
|
else if (FIXNUM_P(x)) {
|
||||||
long ix = FIX2LONG(x);
|
long ix = FIX2LONG(x);
|
||||||
if (ix == 0) {
|
if (ix == 0) {
|
||||||
if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM))
|
if (RB_INTEGER_TYPE_P(y))
|
||||||
return ZERO;
|
return ZERO;
|
||||||
}
|
}
|
||||||
else if (ix == 1)
|
else if (ix == 1)
|
||||||
|
@ -1360,7 +1360,7 @@ encode_year(VALUE nth, int y, double style,
|
|||||||
static void
|
static void
|
||||||
decode_jd(VALUE jd, VALUE *nth, int *rjd)
|
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));
|
*nth = f_idiv(jd, INT2FIX(CM_PERIOD));
|
||||||
if (f_zero_p(*nth)) {
|
if (f_zero_p(*nth)) {
|
||||||
assert(FIXNUM_P(jd));
|
assert(FIXNUM_P(jd));
|
||||||
@ -3133,7 +3133,7 @@ wholenum_p(VALUE x)
|
|||||||
inline static VALUE
|
inline static VALUE
|
||||||
to_integer(VALUE x)
|
to_integer(VALUE x)
|
||||||
{
|
{
|
||||||
if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM))
|
if (RB_INTEGER_TYPE_P(x))
|
||||||
return x;
|
return x;
|
||||||
return f_to_i(x);
|
return f_to_i(x);
|
||||||
}
|
}
|
||||||
|
@ -1504,6 +1504,15 @@ rb_obj_write(VALUE a, VALUE *slot, VALUE b, RB_UNUSED_VAR(const char *filename),
|
|||||||
return a;
|
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
|
#if SIZEOF_INT < SIZEOF_LONG
|
||||||
# define RB_INT2NUM(v) INT2FIX((int)(v))
|
# define RB_INT2NUM(v) INT2FIX((int)(v))
|
||||||
# define RB_UINT2NUM(v) LONG2FIX((unsigned int)(v))
|
# define RB_UINT2NUM(v) LONG2FIX((unsigned int)(v))
|
||||||
|
@ -4037,11 +4037,10 @@ int_comp(VALUE num)
|
|||||||
static int
|
static int
|
||||||
bit_coerce(VALUE *x, VALUE *y)
|
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;
|
VALUE orig = *x;
|
||||||
do_coerce(x, y, TRUE);
|
do_coerce(x, y, TRUE);
|
||||||
if (!FIXNUM_P(*x) && !RB_TYPE_P(*x, T_BIGNUM)
|
if (!RB_INTEGER_TYPE_P(*x) && !RB_INTEGER_TYPE_P(*y)) {
|
||||||
&& !FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) {
|
|
||||||
coerce_failed(orig, *y);
|
coerce_failed(orig, *y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ f_mul(VALUE x, VALUE y)
|
|||||||
if (FIXNUM_P(y)) {
|
if (FIXNUM_P(y)) {
|
||||||
long iy = FIX2LONG(y);
|
long iy = FIX2LONG(y);
|
||||||
if (iy == 0) {
|
if (iy == 0) {
|
||||||
if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM))
|
if (RB_INTEGER_TYPE_P(x))
|
||||||
return ZERO;
|
return ZERO;
|
||||||
}
|
}
|
||||||
else if (iy == 1)
|
else if (iy == 1)
|
||||||
@ -115,7 +115,7 @@ f_mul(VALUE x, VALUE y)
|
|||||||
else if (FIXNUM_P(x)) {
|
else if (FIXNUM_P(x)) {
|
||||||
long ix = FIX2LONG(x);
|
long ix = FIX2LONG(x);
|
||||||
if (ix == 0) {
|
if (ix == 0) {
|
||||||
if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM))
|
if (RB_INTEGER_TYPE_P(y))
|
||||||
return ZERO;
|
return ZERO;
|
||||||
}
|
}
|
||||||
else if (ix == 1)
|
else if (ix == 1)
|
||||||
|
@ -1043,7 +1043,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
|||||||
VALUE val = GETARG(), num, den;
|
VALUE val = GETARG(), num, den;
|
||||||
int sign = (flags&FPLUS) ? 1 : 0, zero = 0;
|
int sign = (flags&FPLUS) ? 1 : 0, zero = 0;
|
||||||
long len, fill;
|
long len, fill;
|
||||||
if (FIXNUM_P(val) || RB_TYPE_P(val, T_BIGNUM)) {
|
if (RB_INTEGER_TYPE_P(val)) {
|
||||||
den = INT2FIX(1);
|
den = INT2FIX(1);
|
||||||
num = val;
|
num = val;
|
||||||
}
|
}
|
||||||
|
2
string.c
2
string.c
@ -2746,7 +2746,7 @@ rb_str_concat(VALUE str1, VALUE str2)
|
|||||||
rb_encoding *enc = STR_ENC_GET(str1);
|
rb_encoding *enc = STR_ENC_GET(str1);
|
||||||
int encidx;
|
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) {
|
if (rb_num_to_uint(str2, &code) == 0) {
|
||||||
}
|
}
|
||||||
else if (FIXNUM_P(str2)) {
|
else if (FIXNUM_P(str2)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user