gh-129275: avoid temporary buffer in dec_as_long()#129630
gh-129275: avoid temporary buffer in dec_as_long()#129630skirpichev wants to merge 1 commit intopython:mainfrom
Conversation
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()).
|
Edit: For a context, Serhiy's concerns about using mpd_sizeinbase() from old pr:
In our case (base is a power of 2) we can avoid using mpd_sizeinbase() and implement more accurate version. Here is the mod_sizeinbase code: cpython/Modules/_decimal/libmpdec/mpdecimal.c Lines 8084 to 8113 in 65ae3d5 Essentially, it does For |
erlend-aasland
left a comment
There was a problem hiding this comment.
Based on the previous PR and discussions, this looks correct to me. I'd like Serhiy's opinion on it, though, since he expressed concerns earlier.
|
@erlend-aasland, It seems that, that Serhiy is still against this change, see the issue thread. So, I'm going to close this in few days, unless someone else can argue further. |
|
Thanks for review to all. |
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()).
Temporary memory allocation slowdown conversion for small integers (~2 digits):
Benchmark hidden because not significant (2): int(Decimal(1<<38)), int(Decimal(1<<3000))
Details