Path as an object in std.path

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 6 10:13:04 PDT 2013


On Thu, 06 Jun 2013 12:14:30 -0400, Dylan Knutson <tcdknutson at gmail.com>  
wrote:

> On Thursday, 6 June 2013 at 16:06:50 UTC, Lars T. Kyllingstad wrote:
>> On Thursday, 6 June 2013 at 14:51:13 UTC, Dylan Knutson wrote:
>>> I should have said "makes it easier to be platform independent".  
>>> Normalization is done automatically on comparison.
>>
>> Yes, p1 == p2 sure looks nice, but unbeknownst to the API user, it  
>> comes at the cost of several memory allocations, and it does not  
>> perform a case-insensitive comparison on Windows in its current form.   
>> (Should it?  I dunno.)
>
> It doesn't do any allocations that the user won't have to do anyways.  
> Paths have to be normalized before comparison; not doing so isn't  
> correct behavior. Eg, the strings `foo../bar` != `bar`, yet they're  
> equivalent paths. Path encapsulates the behavior. So it's the difference  
> between
>
> buildNormalizedPath(s1) == buildNormalizedPath(s2);
>
> and
>
> p1 == p2;

This can be done without allocations.

-Steve


More information about the Digitalmars-d mailing list