summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-02 06:48:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-02 06:48:10 +0000
commitd0b2816d02f49e19a18cbedb7b9f5601ef0b691a (patch)
treeedc31d85ce627372e6b5bf178770c94b0e18fd09 /ext/bigdecimal
parent5fce7630c74fa3cfdfd7a7a3f28af913e5d2a137 (diff)
* ext/bigdecimal/bigdecimal.c (VpAllocReal): reduce extra frac.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 06a424b..749d681 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -554,6 +554,8 @@ VpCreateRbObject(size_t mx, const char *str)
return pv;
}
+#define VpAllocReal(prec) (Real *)VpMemAlloc(offsetof(Real, frac) + (prec) * sizeof(BDIGIT))
+
static Real *
VpDup(Real const* const x)
{
@@ -561,7 +563,7 @@ VpDup(Real const* const x)
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 @@ VpAlloc(size_t mx, const char *szVal)
/* 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 @@ VpAlloc(size_t mx, const char *szVal)
/* 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 @@ VpAlloc(size_t mx, const char *szVal)
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);