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

ruby-changes:21882

From: nobu <ko1@a...>
Date: Fri, 2 Dec 2011 15:48:21 +0900 (JST)
Subject: [ruby-changes:21882] nobu:r33931 (trunk): * ext/bigdecimal/bigdecimal.c (VpAllocReal): reduce extra frac.

nobu	2011-12-02 15:48:10 +0900 (Fri, 02 Dec 2011)

  New Revision: 33931

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

  Log:
    * ext/bigdecimal/bigdecimal.c (VpAllocReal): reduce extra frac.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33930)
+++ ChangeLog	(revision 33931)
@@ -1,3 +1,7 @@
+Fri Dec  2 15:48:08 2011  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/bigdecimal/bigdecimal.c (VpAllocReal): reduce extra frac.
+
 Fri Dec  2 15:41:24 2011  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in: check whether -pie or -Wl,-pie is valid as
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 33930)
+++ ext/bigdecimal/bigdecimal.c	(revision 33931)
@@ -554,6 +554,8 @@
     return pv;
 }
 
+#define VpAllocReal(prec) (Real *)VpMemAlloc(offsetof(Real, frac) + (prec) * sizeof(BDIGIT))
+
 static Real *
 VpDup(Real const* const x)
 {
@@ -561,7 +563,7 @@
 
     assert(x != NULL);
 
-    pv = VpMemAlloc(sizeof(Real) + x->MaxPrec * sizeof(BDIGIT));
+    pv = VpAllocReal(x->MaxPrec);
     pv->MaxPrec = x->MaxPrec;
     pv->Prec = x->Prec;
     pv->exponent = x->exponent;
@@ -3576,7 +3578,7 @@
        /* necessary to be able to store */
        /* at least mx digits. */
        /* szVal==NULL ==> allocate zero value. */
-       vp = (Real *) VpMemAlloc(sizeof(Real) + mx * sizeof(BDIGIT));
+       vp = VpAllocReal(mx);
        /* xmalloc() alway returns(or throw interruption) */
        vp->MaxPrec = mx;    /* set max precision */
        VpSetZero(vp,1);    /* initialize vp to zero. */
@@ -3609,19 +3611,19 @@
     /* Check on Inf & NaN */
     if (StrCmp(szVal, SZ_PINF) == 0 ||
         StrCmp(szVal, SZ_INF)  == 0 ) {
-        vp = (Real *) VpMemAlloc(sizeof(Real) + sizeof(BDIGIT));
+        vp = VpAllocReal(1);
         vp->MaxPrec = 1;    /* set max precision */
         VpSetPosInf(vp);
         return vp;
     }
     if (StrCmp(szVal, SZ_NINF) == 0) {
-        vp = (Real *) VpMemAlloc(sizeof(Real) + sizeof(BDIGIT));
+        vp = VpAllocReal(1);
         vp->MaxPrec = 1;    /* set max precision */
         VpSetNegInf(vp);
         return vp;
     }
     if (StrCmp(szVal, SZ_NaN) == 0) {
-        vp = (Real *) VpMemAlloc(sizeof(Real) + sizeof(BDIGIT));
+        vp = VpAllocReal(1);
         vp->MaxPrec = 1;    /* set max precision */
         VpSetNaN(vp);
         return vp;
@@ -3679,7 +3681,7 @@
     if (mx <= 0) mx = 1;
     nalloc = Max(nalloc, mx);
     mx = nalloc;
-    vp = (Real *) VpMemAlloc(sizeof(Real) + mx * sizeof(BDIGIT));
+    vp = VpAllocReal(mx);
     /* xmalloc() alway returns(or throw interruption) */
     vp->MaxPrec = mx;        /* set max precision */
     VpSetZero(vp, sign);

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

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