[前][次][番号順一覧][スレッド一覧]

ruby-changes:45745

From: shyouhei <ko1@a...>
Date: Thu, 9 Mar 2017 11:31:27 +0900 (JST)
Subject: [ruby-changes:45745] shyouhei:r57818 (trunk): revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]

shyouhei	2017-03-09 11:31:23 +0900 (Thu, 09 Mar 2017)

  New Revision: 57818

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57818

  Log:
    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

  Modified files:
    trunk/bignum.c
    trunk/compile.c
    trunk/include/ruby/ruby.h
    trunk/insns.def
    trunk/internal.h
    trunk/numeric.c
    trunk/object.c
    trunk/sprintf.c
Index: bignum.c
===================================================================
--- bignum.c	(revision 57817)
+++ bignum.c	(revision 57818)
@@ -3184,13 +3184,15 @@ rb_int2big(SIGNED_VALUE n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L3184
 VALUE
 rb_uint2inum(VALUE n)
 {
-    return ULONG2NUM(n);
+    if (POSFIXABLE(n)) return LONG2FIX(n);
+    return rb_uint2big(n);
 }
 
 VALUE
 rb_int2inum(SIGNED_VALUE n)
 {
-    return LONG2NUM(n);
+    if (FIXABLE(n)) return LONG2FIX(n);
+    return rb_int2big(n);
 }
 
 void
Index: compile.c
===================================================================
--- compile.c	(revision 57817)
+++ compile.c	(revision 57818)
@@ -3190,7 +3190,7 @@ case_when_optimizable_literal(NODE *node https://github.com/ruby/ruby/blob/trunk/compile.c#L3190
 	double ival;
 	if (RB_TYPE_P(v, T_FLOAT) &&
 	    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)) {
 	    return v;
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 57817)
+++ sprintf.c	(revision 57818)
@@ -832,7 +832,11 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/sprintf.c#L832
 	      bin_retry:
 		switch (TYPE(val)) {
 		  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;
 		    bignum = 1;
 		    break;
Index: numeric.c
===================================================================
--- numeric.c	(revision 57817)
+++ numeric.c	(revision 57818)
@@ -1279,7 +1279,10 @@ flo_mod(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1279
 static VALUE
 dbl2ival(double d)
 {
-    return rb_dbl2ival(d);
+    if (FIXABLE(d)) {
+	return LONG2FIX((long)d);
+    }
+    return rb_dbl2big(d);
 }
 
 /*
@@ -1964,6 +1967,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L1967
 flo_floor(int argc, VALUE *argv, VALUE num)
 {
     double number, f;
+    long val;
     int ndigits = 0;
 
     if (rb_check_arity(argc, 0, 1)) {
@@ -1980,7 +1984,11 @@ flo_floor(int argc, VALUE *argv, VALUE n https://github.com/ruby/ruby/blob/trunk/numeric.c#L1984
 	return DBL2NUM(f);
     }
     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 https://github.com/ruby/ruby/blob/trunk/numeric.c#L2327
 flo_to_i(VALUE num)
 {
     double f = RFLOAT_VALUE(num);
+    long val;
 
     if (f > 0.0) f = floor(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) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3021
 {
     long v;
 
-    if (FIXNUM_P(val)) {
-	return val;
-    }
-    else if (rb_long_is_fixable_p(v = rb_num2long(val))) {
-	return LONG2FIX(v);
-    }
-    else {
+    if (FIXNUM_P(val)) return val;
+
+    v = rb_num2long(val);
+    if (!FIXABLE(v))
 	rb_raise(rb_eRangeError, "integer %ld out of range of fixnum", v);
-    }
+    return LONG2FIX(v);
 }
 
 #if HAVE_LONG_LONG
Index: object.c
===================================================================
--- object.c	(revision 57817)
+++ object.c	(revision 57818)
@@ -2747,8 +2747,11 @@ rb_convert_to_integer(VALUE val, int bas https://github.com/ruby/ruby/blob/trunk/object.c#L2747
     VALUE tmp;
 
     if (RB_FLOAT_TYPE_P(val)) {
+	double f;
 	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)) {
 	if (base != 0) goto arg_error;
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 57817)
+++ include/ruby/ruby.h	(revision 57818)
@@ -1504,17 +1504,6 @@ rb_integer_type_p(VALUE obj) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1504
 }
 #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
 # define RB_INT2NUM(v) RB_INT2FIX((int)(v))
 # define RB_UINT2NUM(v) RB_LONG2FIX((unsigned int)(v))
@@ -1522,7 +1511,7 @@ rb_long_is_fixable_p(long v) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1511
 static inline VALUE
 rb_int2num_inline(int v)
 {
-    if (rb_long_is_fixable_p(v))
+    if (RB_FIXABLE(v))
 	return RB_INT2FIX(v);
     else
 	return rb_int2big(v);
@@ -1545,7 +1534,7 @@ rb_uint2num_inline(unsigned int v) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1534
 static inline VALUE
 rb_long2num_inline(long v)
 {
-    if (rb_long_is_fixable_p(v))
+    if (RB_FIXABLE(v))
 	return RB_LONG2FIX(v);
     else
 	return rb_int2big(v);
Index: insns.def
===================================================================
--- insns.def	(revision 57817)
+++ insns.def	(revision 57818)
@@ -1345,7 +1345,7 @@ opt_case_dispatch https://github.com/ruby/ruby/blob/trunk/insns.def#L1345
 	    if (RB_FLOAT_TYPE_P(key)) {
 		double kval = RFLOAT_VALUE(key);
 		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)) {
Index: internal.h
===================================================================
--- internal.h	(revision 57817)
+++ internal.h	(revision 57818)
@@ -1383,17 +1383,6 @@ rb_float_new_inline(double d) https://github.com/ruby/ruby/blob/trunk/internal.h#L1383
 #define rb_float_value(v) rb_float_value_inline(v)
 #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 */
 void rb_obj_copy_ivar(VALUE dest, VALUE obj);
 CONSTFUNC(VALUE rb_obj_equal(VALUE obj1, VALUE obj2));

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]