On Friday, 16 March 2012 at 15:41:32 UTC, Timon Gehr wrote:
On 03/16/2012 03:28 PM, H. S. Teoh wrote:
More to the point, does dmd perform this optimization currently?


T


No.

immutable string a = "123";
immutable string b = a;

void main(){writeln(a.ptr is b.ptr);} // "false"

It actually does, but only identical strings. It doesn't seem to do strings within strings.

void foo(string a){
        string b = "123";
        writeln(a is b);
}

void main(){
        string a = "123";
        string b = "456";
        string c = "123456";
        foo(a);
        foo(b);
        foo(c);
}

Prints:
true
false
false

Reply via email to