<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 8 April 2013 13:25, Jacob Carlborg <span dir="ltr"><<a href="mailto:doob@me.com" target="_blank">doob@me.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">On 2013-04-08 10:29, Iain Buclaw wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This information could possibly be helpful.  Though given that most of<br>
(gdc) codegen is on par with g++, there's probably not much on the list<br>
that isn't already detected by the backend optimisation passes.<br>
</blockquote>
<br></div>
Multiple calls to pure functions could be cached.<span class=""><font color="#888888"><br>
<br>
-- <br>
/Jacob Carlborg<br>
</font></span></blockquote></div><br></div><div class="gmail_extra">Not always, but in some circumstances, yes.<br><br>---<br>struct Foo<br>{<br>  int a = 0;<br>  pure int bar (immutable int x)<br>  {<br>    ++a;<br>    return x * 2;<br>
  }<br>}<br><br><br>void main()<br>{<br>  Foo f;<br>  int i = f.bar(2) + f.bar(2);<br><br>  assert (i == 8);<br>  assert (f.a == 2);<br>}<br>---<br><br><br></div><div class="gmail_extra">Again, the characteristics of D pure functions mean that the backend can const-fold away the function entirely under normal optimisations.<br>
<br>---<br>D main ()<br>{<br>  <bb 2>:<br>  # DEBUG f.a => 0<br>  # DEBUG f.a => 1<br>  # DEBUG f.a => 2<br>  # DEBUG i => 8<br>  return 0;<br>}<br>---<br></div><div class="gmail_extra"><br><br></div><div class="gmail_extra">
Possibly strongly-pure functions could be marked as pure in the 'C' sense, but only if they are also nothrow, eg to add to the above example:<br><br>---<br>pure nothrow int baz (Foo f)<br>{<br>  return f.bar(2) + f.bar(2);<br>
}<br>---<br><br></div><div class="gmail_extra"><br clear="all"></div><div class="gmail_extra">Regards<br></div><div class="gmail_extra">-- <br>Iain Buclaw<br><br>*(p < e ? p++ : p) = (c & 0x0f) + '0';
</div></div>