[Python-Dev] Type of range object members

Neal Norwitz nnorwitz at gmail.com
Wed Aug 16 08:46:26 CEST 2006


On 8/15/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>
> That penalty is already paid today. Much code dealing with
> ints has a type test whether it's an int or a long. If
> int and long become subtypes of each other or of some abstract
> type, performance will decrease even more because a subtype
> test is quite expensive if the object is neither int nor
> long (it has to traverse the entire base type hierarchy to
> find out its not inherited from int).

I was playing around with a little patch to avoid that penalty.  It
doesn't take any additional memory, just a handful of bits we aren't
using. :-)

For the more common builtin types, it stores whether it's a subclass
in tp_flags, so there's no function call necessary and it's a constant
time operation.  It was faster when doing simple stuff.  Haven't
thought much whether this is really worthwhile or not.

n
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fast-sub.diff
Type: text/x-diff
Size: 6669 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-dev/attachments/20060815/4a362cc4/attachment.bin 


More information about the Python-Dev mailing list