aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-28 18:42:12 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-28 18:42:12 +0000
commit7caa91737a806884927b06486cb9cf8d740fb1a1 (patch)
tree72f4eaa3ac551406bdf8f528c1f976e527d6e349
parent0721ed92ac9cd87beb6c99563b5f8b08590b5369 (diff)
downloadruby-7caa91737a806884927b06486cb9cf8d740fb1a1.tar.gz
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog14
-rw-r--r--bignum.c24
2 files changed, 22 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index a579b53459..4d69391762 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Wed Jun 29 03:34:41 2016 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* lib/pstore.rb (PStore::CHECKSUM_ALGO): extract the algorithm for
diff --git a/bignum.c b/bignum.c
index 767659d046..741fa2d21e 100644
--- a/bignum.c
+++ b/bignum.c
@@ -5079,10 +5079,8 @@ rb_big2ulong(VALUE x)
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)
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)
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)
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'");
}