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

ruby-changes:29124

From: akr <ko1@a...>
Date: Sat, 8 Jun 2013 20:25:18 +0900 (JST)
Subject: [ruby-changes:29124] akr:r41176 (trunk): * time.c (rb_big_abs_find_maxbit): Use rb_absint_size.

akr	2013-06-08 20:25:07 +0900 (Sat, 08 Jun 2013)

  New Revision: 41176

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41176

  Log:
    * time.c (rb_big_abs_find_maxbit): Use rb_absint_size.
      (bdigit_find_maxbit): Removed.

  Modified files:
    trunk/ChangeLog
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 41175)
+++ time.c	(revision 41176)
@@ -296,47 +296,20 @@ w2v(wideval_t w) https://github.com/ruby/ruby/blob/trunk/time.c#L296
 }
 
 #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;
 }
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41175)
+++ ChangeLog	(revision 41176)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun  8 20:24:23 2013  Tanaka Akira  <akr@f...>
+
+	* 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@r...>
 
 	* class.c (include_modules_at): invalidate method cache if included

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

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