A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-April/088360.html below:

[Python-Dev] pyc files, constant folding and borderline portability issues

[Python-Dev] pyc files, constant folding and borderline portability issuesCesare Di Mauro cesare.dimauro at a-tono.com
Mon Apr 6 18:34:53 CEST 2009
On Lun, Apr 6, 2009 16:43, Antoine Pitrou wrote:
> Cesare Di Mauro <cesare.dimauro <at> a-tono.com> writes:
>> def f(): return ['a', ('b', 'c')] * (1 + 2 * 3)
> [...]
>>
>> With proper constant folding code, both functions can be reduced
>> to a single LOAD_CONST and a RETURN_VALUE (or, definitely, by
>> a single instruction at all with an advanced peephole optimizer).
>
> Lists are mutable, you can't optimize the creation of list literals by
> storing
> them as singleton constants.
>
> Regards
>
> Antoine.

You are right, I've mistyped the example.

def f(): return ('a', ('b', 'c')) * (1 + 2 * 3)

generates a single instruction (depending on the threshold used to limit
folding of sequences), whereas

def f(): return ['a', ('b', 'c')] * (1 + 2 * 3)

needs three.

Sorry for the mistake.

Cheers,
Cesare
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4