@@ -620,21 +620,14 @@ private struct UNIXPath: Path {
620
620
}
621
621
622
622
init ( normalizingRelativePath path: String ) {
623
+ let pathSeparator : Character
623
624
#if os(Windows)
624
- var result : PWSTR ?
625
- defer { LocalFree ( result) }
626
-
627
- _ = path. replacingOccurrences ( of: " / " , with: " \\ " ) . withCString ( encodedAs: UTF16 . self) {
628
- PathAllocCanonicalize ( $0, ULONG ( PATHCCH_ALLOW_LONG_PATHS . rawValue) , & result)
629
- }
630
-
631
- var canonicalized : String = String ( decodingCString: result!, as: UTF16 . self)
632
- if canonicalized == " " || canonicalized == " \\ " {
633
- canonicalized = " . "
634
- }
635
- self . init ( string: canonicalized)
625
+ pathSeparator = " \\ "
626
+ let path = path. replacingOccurrences ( of: " / " , with: " \\ " )
636
627
#else
637
- precondition ( path. first != " / " )
628
+ pathSeparator = " / "
629
+ #endif
630
+ precondition ( path. first != pathSeparator)
638
631
639
632
// FIXME: Here we should also keep track of whether anything actually has
640
633
// to be changed in the string, and if not, just return the existing one.
@@ -644,7 +637,7 @@ private struct UNIXPath: Path {
644
637
// the normalized string representation.
645
638
var parts : [ String ] = [ ]
646
639
var capacity = 0
647
- for part in path. split ( separator: " / " ) {
640
+ for part in path. split ( separator: pathSeparator ) {
648
641
switch part. count {
649
642
case 0 :
650
643
// Ignore empty path components.
@@ -683,7 +676,7 @@ private struct UNIXPath: Path {
683
676
if let first = iter. next ( ) {
684
677
result. append ( contentsOf: first)
685
678
while let next = iter. next ( ) {
686
- result. append ( " / " )
679
+ result. append ( pathSeparator )
687
680
result. append ( contentsOf: next)
688
681
}
689
682
}
@@ -694,7 +687,6 @@ private struct UNIXPath: Path {
694
687
695
688
// If the result is empty, return `.`, otherwise we return it as a string.
696
689
self . init ( string: result. isEmpty ? " . " : result)
697
- #endif
698
690
}
699
691
700
692
init ( validatingAbsolutePath path: String ) throws {
0 commit comments