On Mon, 18 Jul 2011 10:04:26 -0400, Steven Schveighoffer wrote: > On Mon, 18 Jul 2011 09:16:35 -0400, Lars T. Kyllingstad > <public@kyllingen.nospamnet> wrote: > >> On Sun, 17 Jul 2011 12:30:39 +0200, torhu wrote: >> >>> On 15.07.2011 02:20, dsimcha wrote: >>>> Lars Kyllingstad's new and improved std.path module for Phobos is the >>>> next item up in the review queue. I've volunteered to be the review >>>> manager. Barring any objections, the review starts now and ends at >>>> the ends two weeks from now on July 28. This will be followed by a >>>> week of voting, ending August 4th. >>>> >>>> Code: >>>> https://github.com/kyllingstad/phobos/blob/std-path/std/path.d >>>> >>>> Docs: >>>> http://www.kyllingen.net/code/new-std-path/phobos-prerelease/ >> std_path.html >>>> >>>> >>> Looks nice and clean, both docs and code! I like modules that are not >>> overengineered :) >> >> Thanks! >> >> >>> I noticed a couple of things that I don't think have been mentioned >>> already: >>> >>> The docs for defaultExtension say that there's one case where doesn't >>> allocate. But the code says that it always does (.idup isn't >>> conditional, it's just .dup with a different return type). >> >> There is no reason for idup to duplicate an array which is already >> immutable. If it does, I'd say it is a compiler bug. > > No, it has to duplicate. Part of idup is saying "I want an immutable > return" and the other part is saying "I want a duplicate" > > For example: > > string x = "hello".idup; > string y = x; > > assert(x.capacity > 0); // would fail if idup just returned the same > thing x ~= " world"; > > assert(y is x); // would fail. > > The compiler cannot know whether you care or not.
Ah, ok. > If you don't care, why are you calling idup on an immutable array? Just > use it. The specific cases in question are templated functions, where I don't know whether the array is immutable unless I specifically test it. I simply used arr.idup, assuming the compiler would optimise away the duplication when arr is immutable. But it's no big deal to change it to static if (!is(T == immutable)) return arr.idup; -Lars