relocated bigint data table initialization to stix_init()
This commit is contained in:
parent
df3f521220
commit
e519c5078e
@ -654,35 +654,15 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stix_oow_t r1, r2, ub;
|
stix_oow_t r1, r2;
|
||||||
stix_oohw_t multiplier;
|
stix_oohw_t multiplier;
|
||||||
int dg, i, safe_ndigits;
|
int dg, i, safe_ndigits;
|
||||||
|
|
||||||
w = 0;
|
w = 0;
|
||||||
ptr = start;
|
ptr = start;
|
||||||
|
|
||||||
if (stix->bigint[radix].safe_ndigits > 0)
|
safe_ndigits = stix->bigint[radix].safe_ndigits;
|
||||||
{
|
multiplier = stix->bigint[radix].multiplier;
|
||||||
/* if the table entry has been initialized properly,
|
|
||||||
* take it instead of recalculation. */
|
|
||||||
safe_ndigits = stix->bigint[radix].safe_ndigits;
|
|
||||||
multiplier = stix->bigint[radix].multiplier;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r1 = 0;
|
|
||||||
ub = STIX_TYPE_MAX(stix_oohw_t) / radix - (radix - 1);
|
|
||||||
multiplier = 1;
|
|
||||||
for (safe_ndigits = 0; r1 <= ub; safe_ndigits++)
|
|
||||||
{
|
|
||||||
r1 = r1 * radix + (radix - 1);
|
|
||||||
multiplier *= radix;
|
|
||||||
}
|
|
||||||
/* safe_ndigits contains the number of digits that never
|
|
||||||
* cause overflow when computed normally with a native type. */
|
|
||||||
stix->bigint[radix].safe_ndigits = safe_ndigits;
|
|
||||||
stix->bigint[radix].multiplier = multiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
outlen = (end - str) / safe_ndigits + 1;
|
outlen = (end - str) / safe_ndigits + 1;
|
||||||
if (outlen > STIX_COUNTOF(hw))
|
if (outlen > STIX_COUNTOF(hw))
|
||||||
|
@ -56,6 +56,29 @@ void stix_close (stix_t* stix)
|
|||||||
STIX_MMGR_FREE (stix->mmgr, stix);
|
STIX_MMGR_FREE (stix->mmgr, stix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fill_bigint_tables (stix_t* stix)
|
||||||
|
{
|
||||||
|
int radix, safe_ndigits;
|
||||||
|
stix_oow_t multiplier, ub, w;
|
||||||
|
|
||||||
|
for (radix = 2; radix <= 36; radix++)
|
||||||
|
{
|
||||||
|
w = 0;
|
||||||
|
ub = (stix_oow_t)STIX_TYPE_MAX(stix_oohw_t) / radix - (radix - 1);
|
||||||
|
multiplier = 1;
|
||||||
|
for (safe_ndigits = 0; w <= ub; safe_ndigits++)
|
||||||
|
{
|
||||||
|
w = w * radix + (radix - 1);
|
||||||
|
multiplier *= radix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* safe_ndigits contains the number of digits that never
|
||||||
|
* cause overflow when computed normally with a native type. */
|
||||||
|
stix->bigint[radix].safe_ndigits = safe_ndigits;
|
||||||
|
stix->bigint[radix].multiplier = multiplier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int stix_init (stix_t* stix, stix_mmgr_t* mmgr, stix_size_t heapsz, const stix_vmprim_t* vmprim)
|
int stix_init (stix_t* stix, stix_mmgr_t* mmgr, stix_size_t heapsz, const stix_vmprim_t* vmprim)
|
||||||
{
|
{
|
||||||
STIX_MEMSET (stix, 0, STIX_SIZEOF(*stix));
|
STIX_MEMSET (stix, 0, STIX_SIZEOF(*stix));
|
||||||
@ -71,6 +94,8 @@ int stix_init (stix_t* stix, stix_mmgr_t* mmgr, stix_size_t heapsz, const stix_v
|
|||||||
|
|
||||||
if (stix_rbt_init (&stix->pmtable, mmgr, STIX_SIZEOF(stix_ooch_t), 1) <= -1) goto oops;
|
if (stix_rbt_init (&stix->pmtable, mmgr, STIX_SIZEOF(stix_ooch_t), 1) <= -1) goto oops;
|
||||||
stix_rbt_setstyle (&stix->pmtable, stix_getrbtstyle(STIX_RBT_STYLE_INLINE_COPIERS));
|
stix_rbt_setstyle (&stix->pmtable, stix_getrbtstyle(STIX_RBT_STYLE_INLINE_COPIERS));
|
||||||
|
|
||||||
|
fill_bigint_tables (stix);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
oops:
|
oops:
|
||||||
|
@ -704,7 +704,7 @@ struct stix_t
|
|||||||
{
|
{
|
||||||
int safe_ndigits;
|
int safe_ndigits;
|
||||||
stix_oow_t multiplier;
|
stix_oow_t multiplier;
|
||||||
} bigint[36];
|
} bigint[37];
|
||||||
/* == END BIGINT CONVERSION == */
|
/* == END BIGINT CONVERSION == */
|
||||||
|
|
||||||
#if defined(STIX_INCLUDE_COMPILER)
|
#if defined(STIX_INCLUDE_COMPILER)
|
||||||
|
Loading…
Reference in New Issue
Block a user