This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients methane, ncoghlan, rhettinger, stutzbach, terry.reedy
Date 2012-12-23.21:23:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1356297833.84.0.29656090568.issue16712@psf.upfronthosting.co.za>
In-reply-to
Content
Guido put a number of non-optimal implementations in the ABCs.  His goal was to define the interface and to supply a working default implementation (see MutableMapping.clear() for a prime example).

In the case of __reversed__(), it is unfortunate that it slows down the default implementation of reverse().  The latter only runs faster because it is in C, not because of any algorithmic issue.

FWIW, the same is also true of Sequence.__contains__().  This logic in the ABC is straight-forward but slows down the code as compared to Python's C optimizations which can infer a __contains__ method from a sequence that defines __getitem__().

Given that the "issue" isn't algorithmic and is merely a C vs pure Python issue, I recommend leaving the current code as-is.

If someone truly cares about the speed issue, it would be an easy matter to supply a C helper function in the ABCs for speeding-up __reversed__ and __contains__ (for an example of how to do this, see _count_elements() in the collections module).
History
Date User Action Args
2012-12-23 21:23:53rhettingersetrecipients: + rhettinger, terry.reedy, ncoghlan, stutzbach, methane
2012-12-23 21:23:53rhettingersetmessageid: <1356297833.84.0.29656090568.issue16712@psf.upfronthosting.co.za>
2012-12-23 21:23:53rhettingerlinkissue16712 messages
2012-12-23 21:23:53rhettingercreate