Behavior of += (was Re: [Python-Dev] Customization docs)
look at replyto.address.invalid
Tue Jun 4 01:31:41 EDT 2002
Jeff Epler wrote:
> Maybe the bytecode for inplace operations like
> f[i] += v
> should implement the
> _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
More information about the Python-list