@@ -181,8 +181,8 @@ public struct AbsolutePath: Hashable {
181181 public func appending( components names: String ... ) -> AbsolutePath {
182182 // FIXME: This doesn't seem a particularly efficient way to do this.
183183 return names. reduce ( self , { path, name in
184- path. appending ( component: name)
185- } )
184+ path. appending ( component: name)
185+ } )
186186 }
187187
188188 /// NOTE: We will most likely want to add other `appending()` methods, such
@@ -199,28 +199,12 @@ public struct AbsolutePath: Hashable {
199199 /// Root directory (whose string representation is just a path separator).
200200 public static let root = AbsolutePath ( " / " )
201201
202- /// Normalized string representation (the normalization rules are described
203- /// in the documentation of the initializer). This string is never empty.
204- public var asString : String {
205- return _impl. string
206- }
207-
208- // FIXME: We should investigate if it would be more efficient to instead
209- // return a path component iterator that does all its work lazily, moving
210- // from one path separator to the next on-demand.
211- //
212202 /// Returns an array of strings that make up the path components of the
213203 /// absolute path. This is the same sequence of strings as the basenames
214204 /// of each successive path component, starting from the root. Therefore
215205 /// the first path component of an absolute path is always `/`.
216206 public var components : [ String ] {
217- // FIXME: This isn't particularly efficient; needs optimization, and
218- // in fact, it might well be best to return a custom iterator so we
219- // don't have to allocate everything up-front. It would be backed by
220- // the path string and just return a slice at a time.
221- return [ " / " ] + _impl. string. components ( separatedBy: " / " ) . filter ( {
222- !$0. isEmpty
223- } )
207+ return [ " / " ] + _impl. components
224208 }
225209}
226210
@@ -287,34 +271,20 @@ public struct RelativePath: Hashable {
287271 return _impl. extension
288272 }
289273
290- /// Normalized string representation (the normalization rules are described
291- /// in the documentation of the initializer). This string is never empty.
292- public var asString : String {
293- return _impl. string
294- }
295-
296- // FIXME: We should investigate if it would be more efficient to instead
297- // return a path component iterator that does all its work lazily, moving
298- // from one path separator to the next on-demand.
299- //
300274 /// Returns an array of strings that make up the path components of the
301275 /// relative path. This is the same sequence of strings as the basenames
302276 /// of each successive path component. Therefore the returned array of
303277 /// path components is never empty; even an empty path has a single path
304278 /// component: the `.` string.
305279 public var components : [ String ] {
306- // FIXME: This isn't particularly efficient; needs optimization, and
307- // in fact, it might well be best to return a custom iterator so we
308- // don't have to allocate everything up-front. It would be backed by
309- // the path string and just return a slice at a time.
310- return _impl. string. components ( separatedBy: " / " ) . filter ( { !$0. isEmpty } )
280+ return _impl. components
311281 }
312282}
313283
314284extension AbsolutePath : Codable {
315285 public func encode( to encoder: Encoder ) throws {
316286 var container = encoder. singleValueContainer ( )
317- try container. encode ( asString )
287+ try container. encode ( description )
318288 }
319289
320290 public init ( from decoder: Decoder ) throws {
@@ -326,7 +296,7 @@ extension AbsolutePath: Codable {
326296extension RelativePath : Codable {
327297 public func encode( to encoder: Encoder ) throws {
328298 var container = encoder. singleValueContainer ( )
329- try container. encode ( asString )
299+ try container. encode ( description )
330300 }
331301
332302 public init ( from decoder: Decoder ) throws {
@@ -338,23 +308,31 @@ extension RelativePath: Codable {
338308// Make absolute paths Comparable.
339309extension AbsolutePath : Comparable {
340310 public static func < ( lhs: AbsolutePath , rhs: AbsolutePath ) -> Bool {
341- return lhs. asString < rhs. asString
311+ return lhs. description < rhs. description
342312 }
343313}
344314
345- /// Make absolute paths CustomStringConvertible.
346- extension AbsolutePath : CustomStringConvertible {
315+ /// Make absolute paths CustomStringConvertible and CustomDebugStringConvertible .
316+ extension AbsolutePath : CustomStringConvertible , CustomDebugStringConvertible {
347317 public var description : String {
318+ return _impl. string
319+ }
320+
321+ public var debugDescription : String {
348322 // FIXME: We should really be escaping backslashes and quotes here.
349- return " <AbsolutePath: \" \( asString ) \" > "
323+ return " <AbsolutePath: \" \( _impl . string ) \" > "
350324 }
351325}
352326
353- /// Make relative paths CustomStringConvertible.
327+ /// Make relative paths CustomStringConvertible and CustomDebugStringConvertible .
354328extension RelativePath : CustomStringConvertible {
355329 public var description : String {
330+ return _impl. string
331+ }
332+
333+ public var debugDescription : String {
356334 // FIXME: We should really be escaping backslashes and quotes here.
357- return " <RelativePath: \" \( asString ) \" > "
335+ return " <RelativePath: \" \( _impl . string ) \" > "
358336 }
359337}
360338
@@ -416,6 +394,18 @@ private struct PathImpl: Hashable {
416394 return suffix ( withDot: false )
417395 }
418396
397+ // FIXME: We should investigate if it would be more efficient to instead
398+ // return a path component iterator that does all its work lazily, moving
399+ // from one path separator to the next on-demand.
400+ //
401+ fileprivate var components : [ String ] {
402+ // FIXME: This isn't particularly efficient; needs optimization, and
403+ // in fact, it might well be best to return a custom iterator so we
404+ // don't have to allocate everything up-front. It would be backed by
405+ // the path string and just return a slice at a time.
406+ return string. components ( separatedBy: " / " ) . filter ( { !$0. isEmpty } )
407+ }
408+
419409 /// Returns suffix with leading `.` if withDot is true otherwise without it.
420410 private func suffix( withDot: Bool ) -> String ? {
421411 // FIXME: This method seems too complicated; it should be simplified,
0 commit comments