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

ruby-changes:43455

From: naruse <ko1@a...>
Date: Wed, 29 Jun 2016 03:42:21 +0900 (JST)
Subject: [ruby-changes:43455] naruse:r55528 (trunk): * bignum.c (rb_big2ulong): the old logic seems to try to avoid

naruse	2016-06-29 03:42:12 +0900 (Wed, 29 Jun 2016)

  New Revision: 55528

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

  Log:
    * bignum.c (rb_big2ulong): the old logic seems to try to avoid
      calculating `-(long)(num-1)-1` if `num` is not LONG_MIN. (Note that
      `-LONG_MIN` may be larger than LONG_MAX) But C compilers can
      optimize it into single NEG instruction.
      Therefore those two conditions can be single if-body.
    
    * bignum.c (rb_big2long): ditto.
    
    * bignum.c (rb_big2ull): ditto.
    
    * bignum.c (rb_big2ll): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55527)
+++ ChangeLog	(revision 55528)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jun 29 03:34:41 2016  NARUSE, Yui  <naruse@r...>
+
+	* bignum.c (rb_big2ulong): the old logic seems to try to avoid
+	  calculating `-(long)(num-1)-1` if `num` is not LONG_MIN. (Note that
+	  `-LONG_MIN` may be larger than LONG_MAX) But C compilers can
+	  optimize it into single NEG instruction.
+	  Therefore those two conditions can be single if-body.
+
+	* bignum.c (rb_big2long): ditto.
+
+	* bignum.c (rb_big2ull): ditto.
+
+	* bignum.c (rb_big2ll): ditto.
+
 Tue Jun 28 22:55:00 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/pstore.rb (PStore::CHECKSUM_ALGO): extract the algorithm for
Index: bignum.c
===================================================================
--- bignum.c	(revision 55527)
+++ bignum.c	(revision 55528)
@@ -5079,10 +5079,8 @@ rb_big2ulong(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5079
         return num;
     }
     else {
-        if (num <= LONG_MAX)
-            return -(long)num;
-        if (num == 1+(unsigned long)(-(LONG_MIN+1)))
-            return LONG_MIN;
+        if (num <= 1+(unsigned long)(-(LONG_MIN+1)))
+            return -(long)(num-1)-1;
     }
     rb_raise(rb_eRangeError, "bignum out of range of unsigned long");
 }
@@ -5097,10 +5095,8 @@ rb_big2long(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5095
             return num;
     }
     else {
-        if (num <= LONG_MAX)
-            return -(long)num;
-        if (num == 1+(unsigned long)(-(LONG_MIN+1)))
-            return LONG_MIN;
+        if (num <= 1+(unsigned long)(-(LONG_MIN+1)))
+            return -(long)(num-1)-1;
     }
     rb_raise(rb_eRangeError, "bignum too big to convert into `long'");
 }
@@ -5139,10 +5135,8 @@ rb_big2ull(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5135
         return num;
     }
     else {
-        if (num <= LLONG_MAX)
-            return -(LONG_LONG)num;
-        if (num == 1+(unsigned LONG_LONG)(-(LLONG_MIN+1)))
-            return LLONG_MIN;
+        if (num <= 1+(unsigned LONG_LONG)(-(LLONG_MIN+1)))
+            return -(LONG_LONG)(num-1)-1;
     }
     rb_raise(rb_eRangeError, "bignum out of range of unsigned long long");
 }
@@ -5157,10 +5151,8 @@ rb_big2ll(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5151
             return num;
     }
     else {
-        if (num <= LLONG_MAX)
-            return -(LONG_LONG)num;
-        if (num == 1+(unsigned LONG_LONG)(-(LLONG_MIN+1)))
-            return LLONG_MIN;
+        if (num <= 1+(unsigned LONG_LONG)(-(LLONG_MIN+1)))
+            return -(LONG_LONG)(num-1)-1;
     }
     rb_raise(rb_eRangeError, "bignum too big to convert into `long long'");
 }

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

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