Behavior of += (was Re: [Python-Dev] Customization docs)

David Abrahams david.abrahams at rcn.com
Tue Jun 4 08:01:56 EDT 2002


Funny that this topic should come up over here, since:

http://aspn.activestate.com/ASPN/Mail/Message/python-dev/1222411

minds-think-alike-ly y'rs,
dave

"Greg Ewing" <look at replyto.address.invalid> wrote in message
news:3CFC50BD.CB9CB70C at replyto.address.invalid...
> Jeff Epler wrote:
> >
> > Maybe the bytecode for inplace operations like
> >     f[i] += v
> > should implement the
> > pseudocode
> >     _temp = f[i]
> >     _new = inplace_add(_temp, v)
> >     if _new is not _temp:
> >         f[i] = _new
> >     del _temp, _new
>
> That's a nice idea...
>
> > However, this would probably double the bytecode size of the sequence,
> > and hurt performance similarly....
>
> It needn't, if:
>
> (1) the INPLACE_xxx bytecodes leave the first operand
>     on the stack
>
> (2) there are new STORE_xxx_IF_UNCHANGED bytecodes that
>     compare the value to be stored with the previous one.
>
> The total number of bytecodes should then be the same,
> and all the new work would be done in C code, which
> ought to be pretty fast (a pointer comparison and
> a few extra inc/decrefs).
>
> --
> Greg Ewing, Computer Science Dept,
> University of Canterbury,
> Christchurch, New Zealand
> http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list