[Python-3000] optimizing [x]range

Guido van Rossum guido at python.org
Fri Aug 3 19:06:06 CEST 2007


On 8/3/07, Stargaming <stargaming at gmail.com> wrote:
> On Thu, 02 Aug 2007 15:25:36 -0700, Guido van Rossum wrote:
>
> > On 8/2/07, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> >> > The patch is based on the latest trunk/ checkout, Python 2.6. I don't
> >> > think this is a problem if nobody else made any effort towards making
> >> > xrange more sequence-like in the Python 3000 branch. The C source
> >> > might require some tab/space cleanup.
> >>
> >> Unfortunately, this is exactly what happened: In Py3k, the range object
> >> is defined in terms PyObject*, so your patch won't apply to the 3k
> >> branch.
> >
> > FWIW, making xrange (or range in Py3k) "more sequence-like" is exactly
> > what should *not* happen.
>
> No, that's exactly what *should* happen for optimization reasons.
>
> xrange has never (neither in 2.6 nor 3.0) had an sq_contains slot.
> Growing such a slot is a precondition for implementing
> xrange.__contains__ as an optimized special case, and that makes it more
> sequence-like on the side of the implementation. This does not mean it
> becomes more like the 2.x range, which we're abandoning.
> Sorry for the confusion.

OK, gotcha. I was just warning not to add silliness like slicing.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list