Chris's Wiki :: blog/python/ExaminingStringConcatOpt Commentshttps://utcc.utoronto.ca/~cks/space/blog/python/ExaminingStringConcatOpt?atomcommentsDWiki2005-11-07T23:38:55ZRecent comments in Chris's Wiki :: blog/python/ExaminingStringConcatOpt.From 71.141.238.136 on /blog/python/ExaminingStringConcatOpttag:CSpace:blog/python/ExaminingStringConcatOpt:6338023df87b19de1a7b18303f765d47812e7565From 71.141.238.136<div class="wikitext"><p>Note that the aliasing issue is unlikely to be a significant barrier to optimizing <em>repeated</em> concatenation; any code along the lines of
</p>
<pre>
foo = first_item
bar = foo
for z in some_list
foo = foo + z
baz = foo
</pre>
<p>might not get an optimization on the <em>first</em> iteration, because foo is aliased; but after that foo becomes unaliased, and thus is optimizable. Thus if there would normally be N temps generated, the optimization may reduce it to only 1 temp generated.
</p>
<p>For aliasing to prevent the optimization, you'd have to alias each temporary as its generated. Possibly this might happen if you used a recursive algorithm rather than an iterative one, but it seems unlikely in the iterative case.
</p>
<p>--nothings</p>
</div>2005-11-07T23:38:55Z