You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After #127925, new code in the decimal module (using the PEP 757) do temporary allocation with mpdecimal's memory functions (in mpd_qexport_u32/16()), just as before:
According to the documentation, we can prepare array of digits, which size could be estimated by mpd_sizeinbase(). Given this, the mpd_qexport_u32/16() shouldn't do any resize for this array. Here is Stefan comment on how safe this approach is:
mpd_sizeinbase() uses log10() from math.h for performance reasons. If log10() is IEEE compliant, the result should be sufficiently large. Resizing is for guarding against broken log10() implementations.
The current code in _decimal.c sets the libmpdec allocation functions to PyMem_Malloc() etc. So if longobject uses PyMem_Free() it is safe even when resizing occurs.
If the new API allows for allocators other that PyMem_Malloc(), it will rely on the IEEE compliance of log10().
Stefan Krah
We can expect slight performance boost for small (2-3 digits) integers.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
According to the documentation: "If rdata is non-NULL, it MUST be
allocated by one of libmpdec’s allocation functions and rlen MUST be
correct. If necessary, the function will resize rdata. Resizing is
slow and should not occur if rlen has been obtained by a call to
mpd_sizeinbase."
So, possible resizing in mpd_qexport_u32/16() is for guarding against
broken log10() implementations (log10 is used in the mpd_sizeinbase()).
Feature or enhancement
Proposal:
After #127925, new code in the decimal module (using the PEP 757) do temporary allocation with mpdecimal's memory functions (in mpd_qexport_u32/16()), just as before:
cpython/Modules/_decimal/_decimal.c
Lines 3691 to 3706 in f10b7b2
According to the documentation, we can prepare array of digits, which size could be estimated by mpd_sizeinbase(). Given this, the mpd_qexport_u32/16() shouldn't do any resize for this array. Here is Stefan comment on how safe this approach is:
We can expect slight performance boost for small (2-3 digits) integers.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: