summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-08 11:25:07 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-08 11:25:07 +0000
commitaf612be8e0e54ffa602cede04d355a1399a02b81 (patch)
treee261bb1c567eeafa04797b4ce8effb509e2461a0
parentb512e61ca02ad5ebdfb08581e87bbc0791009684 (diff)
* time.c (rb_big_abs_find_maxbit): Use rb_absint_size.
(bdigit_find_maxbit): Removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--time.c45
2 files changed, 14 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 616887e9a6..cea5907e11 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Jun 8 20:24:23 2013 Tanaka Akira <akr@fsij.org>
+
+ * time.c (rb_big_abs_find_maxbit): Use rb_absint_size.
+ (bdigit_find_maxbit): Removed.
+
Sat Jun 8 19:47:00 2013 Charlie Somerville <charliesome@ruby-lang.org>
* class.c (include_modules_at): invalidate method cache if included
diff --git a/time.c b/time.c
index ff19728d1c..68c5384067 100644
--- a/time.c
+++ b/time.c
@@ -296,47 +296,20 @@ w2v(wideval_t w)
}
#if WIDEVALUE_IS_WIDER
-static int
-bdigit_find_maxbit(BDIGIT d)
-{
- int res = 0;
- if (d & ~(BDIGIT)0xffff) {
- d >>= 16;
- res += 16;
- }
- if (d & ~(BDIGIT)0xff) {
- d >>= 8;
- res += 8;
- }
- if (d & ~(BDIGIT)0xf) {
- d >>= 4;
- res += 4;
- }
- if (d & ~(BDIGIT)0x3) {
- d >>= 2;
- res += 2;
- }
- if (d & ~(BDIGIT)0x1) {
- d >>= 1;
- res += 1;
- }
- return res;
-}
-
static VALUE
rb_big_abs_find_maxbit(VALUE big)
{
- BDIGIT *ds = RBIGNUM_DIGITS(big);
- BDIGIT d;
- long len = RBIGNUM_LEN(big);
+ int num_zeros;
+ size_t bytesize;
VALUE res;
- while (0 < len && ds[len-1] == 0)
- len--;
- if (len == 0)
+
+ bytesize = rb_absint_size(big, &num_zeros);
+ if (bytesize == 0)
return Qnil;
- res = mul(LONG2NUM(len-1), INT2FIX(SIZEOF_BDIGITS * CHAR_BIT));
- d = ds[len-1];
- res = add(res, LONG2FIX(bdigit_find_maxbit(d)));
+
+ res = mul(SIZET2NUM(bytesize), LONG2FIX(CHAR_BIT));
+ if (num_zeros)
+ res = sub(res, LONG2FIX(num_zeros));
return res;
}