1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]

This commit is auto-generated using following command:

svn diff -r57807:57788 include internal.h bignum.c numeric.c compile.c insns.def object.c sprintf.c | patch -p0


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shyouhei 2017-03-09 02:31:23 +00:00
parent 35fde4da0b
commit c56edb9a59
8 changed files with 38 additions and 41 deletions

View file

@ -3184,13 +3184,15 @@ rb_int2big(SIGNED_VALUE n)
VALUE VALUE
rb_uint2inum(VALUE n) rb_uint2inum(VALUE n)
{ {
return ULONG2NUM(n); if (POSFIXABLE(n)) return LONG2FIX(n);
return rb_uint2big(n);
} }
VALUE VALUE
rb_int2inum(SIGNED_VALUE n) rb_int2inum(SIGNED_VALUE n)
{ {
return LONG2NUM(n); if (FIXABLE(n)) return LONG2FIX(n);
return rb_int2big(n);
} }
void void

View file

@ -3190,7 +3190,7 @@ case_when_optimizable_literal(NODE *node)
double ival; double ival;
if (RB_TYPE_P(v, T_FLOAT) && if (RB_TYPE_P(v, T_FLOAT) &&
modf(RFLOAT_VALUE(v), &ival) == 0.0) { modf(RFLOAT_VALUE(v), &ival) == 0.0) {
return rb_dbl2ival(ival); return FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival);
} }
if (SYMBOL_P(v) || rb_obj_is_kind_of(v, rb_cNumeric)) { if (SYMBOL_P(v) || rb_obj_is_kind_of(v, rb_cNumeric)) {
return v; return v;

View file

@ -1504,17 +1504,6 @@ rb_integer_type_p(VALUE obj)
} }
#endif #endif
static inline int
rb_long_is_fixable_p(long v)
{
#ifdef HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW
SIGNED_VALUE w;
return! __builtin_add_overflow(v, v, &w);
#else
return RB_FIXABLE(v);
#endif
}
#if SIZEOF_INT < SIZEOF_LONG #if SIZEOF_INT < SIZEOF_LONG
# define RB_INT2NUM(v) RB_INT2FIX((int)(v)) # define RB_INT2NUM(v) RB_INT2FIX((int)(v))
# define RB_UINT2NUM(v) RB_LONG2FIX((unsigned int)(v)) # define RB_UINT2NUM(v) RB_LONG2FIX((unsigned int)(v))
@ -1522,7 +1511,7 @@ rb_long_is_fixable_p(long v)
static inline VALUE static inline VALUE
rb_int2num_inline(int v) rb_int2num_inline(int v)
{ {
if (rb_long_is_fixable_p(v)) if (RB_FIXABLE(v))
return RB_INT2FIX(v); return RB_INT2FIX(v);
else else
return rb_int2big(v); return rb_int2big(v);
@ -1545,7 +1534,7 @@ rb_uint2num_inline(unsigned int v)
static inline VALUE static inline VALUE
rb_long2num_inline(long v) rb_long2num_inline(long v)
{ {
if (rb_long_is_fixable_p(v)) if (RB_FIXABLE(v))
return RB_LONG2FIX(v); return RB_LONG2FIX(v);
else else
return rb_int2big(v); return rb_int2big(v);

View file

@ -1345,7 +1345,7 @@ opt_case_dispatch
if (RB_FLOAT_TYPE_P(key)) { if (RB_FLOAT_TYPE_P(key)) {
double kval = RFLOAT_VALUE(key); double kval = RFLOAT_VALUE(key);
if (!isinf(kval) && modf(kval, &kval) == 0.0) { if (!isinf(kval) && modf(kval, &kval) == 0.0) {
key = rb_dbl2ival(kval); key = FIXABLE(kval) ? LONG2FIX((long)kval) : rb_dbl2big(kval);
} }
} }
if (st_lookup(RHASH_TBL_RAW(hash), key, &val)) { if (st_lookup(RHASH_TBL_RAW(hash), key, &val)) {

View file

@ -1383,17 +1383,6 @@ rb_float_new_inline(double d)
#define rb_float_value(v) rb_float_value_inline(v) #define rb_float_value(v) rb_float_value_inline(v)
#define rb_float_new(d) rb_float_new_inline(d) #define rb_float_new(d) rb_float_new_inline(d)
static inline VALUE
rb_dbl2ival(double d)
{
if (RB_FIXABLE(d)) {
return LONG2FIX((long)d);
}
else {
return rb_dbl2big(d);
}
}
/* object.c */ /* object.c */
void rb_obj_copy_ivar(VALUE dest, VALUE obj); void rb_obj_copy_ivar(VALUE dest, VALUE obj);
CONSTFUNC(VALUE rb_obj_equal(VALUE obj1, VALUE obj2)); CONSTFUNC(VALUE rb_obj_equal(VALUE obj1, VALUE obj2));

View file

@ -1279,7 +1279,10 @@ flo_mod(VALUE x, VALUE y)
static VALUE static VALUE
dbl2ival(double d) dbl2ival(double d)
{ {
return rb_dbl2ival(d); if (FIXABLE(d)) {
return LONG2FIX((long)d);
}
return rb_dbl2big(d);
} }
/* /*
@ -1964,6 +1967,7 @@ static VALUE
flo_floor(int argc, VALUE *argv, VALUE num) flo_floor(int argc, VALUE *argv, VALUE num)
{ {
double number, f; double number, f;
long val;
int ndigits = 0; int ndigits = 0;
if (rb_check_arity(argc, 0, 1)) { if (rb_check_arity(argc, 0, 1)) {
@ -1980,7 +1984,11 @@ flo_floor(int argc, VALUE *argv, VALUE num)
return DBL2NUM(f); return DBL2NUM(f);
} }
f = floor(number); f = floor(number);
return dbl2ival(f); if (!FIXABLE(f)) {
return rb_dbl2big(f);
}
val = (long)f;
return LONG2FIX(val);
} }
/* /*
@ -2319,11 +2327,16 @@ static VALUE
flo_to_i(VALUE num) flo_to_i(VALUE num)
{ {
double f = RFLOAT_VALUE(num); double f = RFLOAT_VALUE(num);
long val;
if (f > 0.0) f = floor(f); if (f > 0.0) f = floor(f);
if (f < 0.0) f = ceil(f); if (f < 0.0) f = ceil(f);
return dbl2ival(f); if (!FIXABLE(f)) {
return rb_dbl2big(f);
}
val = (long)f;
return LONG2FIX(val);
} }
/* /*
@ -3008,15 +3021,12 @@ rb_num2fix(VALUE val)
{ {
long v; long v;
if (FIXNUM_P(val)) { if (FIXNUM_P(val)) return val;
return val;
} v = rb_num2long(val);
else if (rb_long_is_fixable_p(v = rb_num2long(val))) { if (!FIXABLE(v))
return LONG2FIX(v);
}
else {
rb_raise(rb_eRangeError, "integer %ld out of range of fixnum", v); rb_raise(rb_eRangeError, "integer %ld out of range of fixnum", v);
} return LONG2FIX(v);
} }
#if HAVE_LONG_LONG #if HAVE_LONG_LONG

View file

@ -2747,8 +2747,11 @@ rb_convert_to_integer(VALUE val, int base)
VALUE tmp; VALUE tmp;
if (RB_FLOAT_TYPE_P(val)) { if (RB_FLOAT_TYPE_P(val)) {
double f;
if (base != 0) goto arg_error; if (base != 0) goto arg_error;
return rb_dbl2ival(RFLOAT_VALUE(val)); f = RFLOAT_VALUE(val);
if (FIXABLE(f)) return LONG2FIX((long)f);
return rb_dbl2big(f);
} }
else if (RB_INTEGER_TYPE_P(val)) { else if (RB_INTEGER_TYPE_P(val)) {
if (base != 0) goto arg_error; if (base != 0) goto arg_error;

View file

@ -832,7 +832,11 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
bin_retry: bin_retry:
switch (TYPE(val)) { switch (TYPE(val)) {
case T_FLOAT: case T_FLOAT:
val = rb_dbl2ival(RFLOAT_VALUE(val)); if (FIXABLE(RFLOAT_VALUE(val))) {
val = LONG2FIX((long)RFLOAT_VALUE(val));
goto bin_retry;
}
val = rb_dbl2big(RFLOAT_VALUE(val));
if (FIXNUM_P(val)) goto bin_retry; if (FIXNUM_P(val)) goto bin_retry;
bignum = 1; bignum = 1;
break; break;