[Style] Converting from char[] to string, to!string vs idup

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Mar 25 16:13:07 PDT 2014


On Tue, Mar 25, 2014 at 10:02:33PM +0000, monarch_dodra wrote:
> On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote:
> >Is there a performance benefit? Is it simply because it's more general?
[...]
> There is *1* thing you should take into account though: "to!" is a
> no-op for string=>string or char[]=>char[], or anything else that can
> be implicitly converted as such. In contrast, "dup"/"idup" will create
> an actual copy.
> 
> Not that this is good or bad. Just something you should keep in mind.

I think it's a good thing. It avoids needless copying where it's not
necessary. (Of course, if you have a char[] and you actually want a new
copy, then you have to use .dup explicitly.)


T

-- 
Маленькие детки - маленькие бедки.


More information about the Digitalmars-d-learn mailing list