[issue27298] redundant iteration over digits in _PyLong_AsUnsignedLongMask

Oren Milman report at bugs.python.org
Tue Jun 14 16:44:50 EDT 2016


Oren Milman added the comment:

Ah, that's a cool alternative to divide and ceil. I would change my patch accordingly.

And would write the patch also for _PyLong_AsUnsignedLongLongMask, and work on some micro-benchmarking for it and _PyLong_AsUnsignedLongMask.

Indeed _testcapimodule.c is not really related. Should I open another issue for that only?
(I am often worried about opening many small issues.. Please let me know if I shouldn't be.)

Now that you mention it, similar 'while (--i >= 0)' can be found in some other functions:
1. PyLong_AsLongAndOverflow
2. PyLong_AsSsize_t
3. PyLong_AsUnsignedLong
4. PyLong_AsSize_t
5. PyLong_AsLongLongAndOverflow
I suspect we could optimize these 5 by first determining whether the Python int has too many bits, instead of shifting and checking for an overflow on each iteration. 
I would definitely give it a try when I am done with _PyLong_AsUnsignedLongLongMask and _PyLong_AsUnsignedLongMask :)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27298>
_______________________________________


More information about the Python-bugs-list mailing list