@@ -2335,24 +2335,18 @@ dec_from_long(decimal_state *state, PyTypeObject *type, PyObject *v,
23352335 return NULL ;
23362336 }
23372337 if (export_long .digits ) {
2338- const PyLongLayout * layout = PyLong_GetNativeLayout ();
2339- const uint8_t bpd = layout -> bits_per_digit ;
23402338 const uint8_t sign = export_long .negative ? MPD_NEG : MPD_POS ;
23412339 const Py_ssize_t len = export_long .ndigits ;
23422340
2343- if (bpd == 30 ) {
2344- mpd_qimport_u32 (MPD (dec ), export_long .digits , len , sign ,
2345- 1 << bpd , ctx , status );
2346- }
2347- else if (bpd == 15 ) {
2348- mpd_qimport_u16 (MPD (dec ), export_long .digits , len , sign ,
2349- 1 << bpd , ctx , status );
2350- }
2351- else {
2352- PyLong_FreeExport (& export_long );
2353- Py_DECREF (dec );
2354- return NULL ;
2355- }
2341+ #if PYLONG_BITS_IN_DIGIT == 30
2342+ mpd_qimport_u32 (MPD (dec ), export_long .digits , len , sign ,
2343+ PyLong_BASE , ctx , status );
2344+ #elif PYLONG_BITS_IN_DIGIT == 15
2345+ mpd_qimport_u16 (MPD (dec ), export_long .digits , len , sign ,
2346+ PyLong_BASE , ctx , status );
2347+ #else
2348+ #error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
2349+ #endif
23562350 PyLong_FreeExport (& export_long );
23572351 }
23582352 else {
@@ -3648,7 +3642,6 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
36483642 mpd_t * x ;
36493643 mpd_context_t workctx ;
36503644 uint32_t status = 0 ;
3651- const PyLongLayout * layout = PyLong_GetNativeLayout ();
36523645
36533646 if (mpd_isspecial (MPD (dec ))) {
36543647 if (mpd_isnan (MPD (dec ))) {
@@ -3683,8 +3676,7 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
36833676 return PyLong_FromInt64 (val );
36843677 }
36853678
3686- const uint8_t bpd = layout -> bits_per_digit ;
3687- n = (mpd_sizeinbase (x , 2 ) + bpd - 1 ) / bpd ;
3679+ n = (mpd_sizeinbase (x , 2 ) + PyLong_SHIFT - 1 )/PyLong_SHIFT ;
36883680 PyLongWriter * writer = PyLongWriter_Create (mpd_isnegative (x ), n ,
36893681 (void * * )& ob_digit );
36903682 /* mpd_sizeinbase can overestimate size by 1 digit, set it to zero. */
0 commit comments