To help LDC/GDC
deadalnix
deadalnix at gmail.com
Mon Apr 8 17:44:41 PDT 2013
On Monday, 8 April 2013 at 15:07:31 UTC, Jacob Carlborg wrote:
> On 2013-04-08 14:52, Iain Buclaw wrote:
>> On 8 April 2013 13:25, Jacob Carlborg <doob at me.com
>> <mailto:doob at me.com>>
>> wrote:
>>
>> On 2013-04-08 10:29, Iain Buclaw wrote:
>>
>> This information could possibly be helpful. Though
>> given that
>> most of
>> (gdc) codegen is on par with g++, there's probably not
>> much on
>> the list
>> that isn't already detected by the backend optimisation
>> passes.
>>
>>
>> Multiple calls to pure functions could be cached.
>>
>> --
>> /Jacob Carlborg
>>
>>
>> Not always, but in some circumstances, yes.
>>
>> ---
>> struct Foo
>> {
>> int a = 0;
>> pure int bar (immutable int x)
>> {
>> ++a;
>> return x * 2;
>> }
>> }
>>
>>
>> void main()
>> {
>> Foo f;
>> int i = f.bar(2) + f.bar(2);
>>
>> assert (i == 8);
>> assert (f.a == 2);
>> }
>
> I though that wasn't possible. What's the point of pure if
> that's possible?
You have to think that this is an hidden parameter. The function
touch that parameter, no global state.
More information about the Digitalmars-d
mailing list