[issue3236] ints contructed from strings don't use the smallint constants

Antoine Pitrou report at bugs.python.org
Sun Jun 29 23:17:49 CEST 2008


Antoine Pitrou <pitrou at free.fr> added the comment:

Le dimanche 29 juin 2008 à 17:43 +0000, Martin v. Löwis a écrit :
> For long, it's much more tricky, as no C type can be used to store the
> intermediate result. So instead, PyLong_FromString already allocates a
> sufficiently-sized long object (based on the number of digits of the
> input string), and then fills that object.
> 
> Depending on what precisely the complaint of this report is about, one
> solution could be to check after the conversion whether the result has
> only one digit, and if so, whether it is a small integer, and if so,
> convert it to a long, discard it, and use PyLong_FromLong.
> 
> If the complaint is that it unnecessarily allocates memory in the first
> place, I don't think anything should be done about that - the allocation
> is really necessary.

The bug entry is just for pointing out a missed optimization
opportunity. The first mentioned solution would already be an
improvement, although of course it would even be better to skip the
intermediary allocation altogether.

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


More information about the Python-bugs-list mailing list