DIP74: Reference Counted Class Objects
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sun Mar 1 07:39:13 PST 2015
On 3/1/15 6:55 AM, John Colvin wrote:
> On Sunday, 1 March 2015 at 03:43:24 UTC, Andrei Alexandrescu wrote:
>> It might be more productive to look into improvements of optimizations
>> related to copying objects.
>>
>>
>> Andrei
>
> Yes please. I'd be very interested in hearing any thoughts you have on
> this.
One that comes to mind is: if (a) a copy b of a struct object a is
created, (b) b is used only with non-mutating operations, and (c) a is
not changed before b goes out of scope, then a can be directly
substituted for b (no actual copy is made).
Example:
struct S {
this(this);
~this();
int method() const;
}
int fun() {
S a;
S b = a;
return b.method();
}
may be lowered to:
int fun() {
S a;
return a.method();
}
Andrei
More information about the Digitalmars-d
mailing list