[Python-3000] optimizing [x]range

tomer filiba tomerfiliba at gmail.com
Sun Jul 29 20:06:47 CEST 2007


On 7/29/07, Guido van Rossum <guido at python.org> wrote:
> Don't forget the *cost* in terms of code bloat. Plus, I asked for a
> patch. Where is it? This is not Santa Claus's email address. You're
> expected to contribute more than a wish.

first off all, that's not the politest way to put it, especially since i have
submitted some patches before. second, i've already given a 3-line
implementation in python. it would only take two minutes to convert
it to C, save the unit tests. third, i'm busy over my head studying of
my exams. forth, due to lack of public interest, i might as well
withdraw this.

> Um, your range "solution" would break for examples like 2**100 in
> evens (it's hard to think of a more even number than that. :-)

there's no reason why (x)range shouldn't support longs too.
after all, it only tests for modulo internally (*unlike* how it works
today, which will never finish).

besides, that's not the point. i'm only saying there's no reason that
testing for containment in range objects (which are no longer lists),
should be O(N), when it can easily be made O(1) in under 10 lines of C
code.

> But I still see no reason to make it O(1).

as you wish.
*goes back in time and withdraws the proposal*


-tomer


More information about the Python-3000 mailing list