On Thursday, 5 December 2013 at 08:09:55 UTC, monarch_dodra wrote:
On Wednesday, 4 December 2013 at 23:14:48 UTC, Andrei Alexandrescu wrote:
Hello,


Walter and I were talking about eliminating the surreptitious allocations in buildPath:

http://dlang.org/phobos/std_path.html#.buildPath

We'd need to keep the existing version working, so we're looking at adding one or more new overloads. We're looking at giving the user the option to control any needed memory allocation (or even arrange things such that there's no memory allocated at all).

It's a generous design space, so although we have a couple of ideas let's hear others first.


Thanks,

Andrei

Use an output range. It's the generic D approach, and what we already do for the string functions such as std.string.translate:
http://dlang.org/phobos/std_string.html#.translate
(look down for the output range overloads).

Anything "allocator" related should be carried by the output range itself. The function itself should not care nor know about any of that.

And thanks to your improvements[1] to put() output ranges should actually be much more usable than they ever were before. I've mentioned this a few times but I tried to add an output range overload of toUpper and toLower but immediately encountered problems with appending dchars to char arrays. Your recently merged improvements to put() appear to have addressed that problem and many others and I'll soon have another go at adding these overloads now that that change is in place so thanks for doing the hard work.

Before this got merged I don't even think output ranges could be easily used for this improvement to buildPath so it got merged at a very convenient time.

(my memory is a bit poor but if I'm remembering correctly appender worked because it had done its own handling of narrow strings but you couldn't just use a static or dynamic narrow string array as an output range)

1. https://github.com/D-Programming-Language/phobos/pull/1569

Reply via email to