Optimising literals away

Cameron Simpson cs at zip.com.au
Wed Sep 1 03:22:45 CEST 2010

On 31Aug2010 23:38, MRAB <python at mrabarnett.plus.com> wrote:
| On 31/08/2010 23:11, Cameron Simpson wrote:
| >On 31Aug2010 22:53, MRAB<python at mrabarnett.plus.com>  wrote:
| >| There's still the possibility of some optimisation. If the resulting
| >| set is never stored anywhere (bound to a name, for example) then it
| >| could be created once. When the expression is evaluated there could be
| >| a check so see whether 'set' is bound to the built-in class, and, if it
| >| is, then just use the pre-created set.
| >
| >Wouldn't you need to repeat that check every time, otherwise "set" may
| >no longer be the builtin?
| Isn't that what I said?

Yes. It's not what my brain decided to read to me.

| My point is that if you have a set of constants which is created and
| then discarded you can cache it and reuse it next time. You check every
| time whether 'set' is bound to the set class.

Ok then. I was thinking, for some reason, a JIT-like behaviour that
didn't just reuse the previously made set but replaced the set([1,2,3])
itself, thus omitting the test you mentioned:-(

Cameron Simpson <cs at zip.com.au> DoD#743

It's hard to make a man understand something when his livelihood depends
on him not understanding it. - Upton Sinclair

More information about the Python-list mailing list