[Python-3000] Fwd: Re: rename it.next() to it.__next__(), add a next() built-in
"Martin v. Löwis"
martin at v.loewis.de
Tue Mar 6 12:40:03 CET 2007
Raymond Hettinger schrieb:
>> Invoking a builtin .next() method via a protocol
>> function shouldn't be any slower than it is now.
>> In both cases you've got one name lookup and one
>> Python call, after which you go through the type
>> slot directly to a C function.
> Do you expect that next(someiterator) will be just
> as fast and calling a boundmethod (such as:
> counter=itertools.counter(1); counter())?
I would think so, yes. counter will be a method-wrapper,
calling it will create an empty argument tuple (or
rather pass the singleton one), this will call wrap_next,
which will call count_next.
A builtin (or otherwise global) next() function will be
METH_O, so no argument tuple is created, and tp_iternext
is invoked directly.
As no memory allocation should happen in either case, and
all checks are pretty fast, the difference should be minor,
More information about the Python-3000