[stdlib] Extract Array._makeDescription into standalone function

This enables its use for collection types unrelated to Arrays.
Use the new function to replace Set’s implementation of
Custom[Debug]StringConvertible.
This commit is contained in:
Karoy Lorentey
2017-10-03 16:48:25 +01:00
parent ee062566ca
commit e4ef5203d2
2 changed files with 35 additions and 46 deletions

View File

@@ -1322,33 +1322,16 @@ extension Set {
}
extension Set : CustomStringConvertible, CustomDebugStringConvertible {
@_inlineable // FIXME(sil-serialize-all)
@_versioned // FIXME(sil-serialize-all)
internal func makeDescription(isDebug: Bool) -> String {
var result = isDebug ? "Set([" : "["
var first = true
for member in self {
if first {
first = false
} else {
result += ", "
}
debugPrint(member, terminator: "", to: &result)
}
result += isDebug ? "])" : "]"
return result
}
/// A string that represents the contents of the set.
@_inlineable // FIXME(sil-serialize-all)
public var description: String {
return makeDescription(isDebug: false)
return _makeCollectionDescription(for: self, withTypeName: nil)
}
/// A string that represents the contents of the set, suitable for debugging.
@_inlineable // FIXME(sil-serialize-all)
public var debugDescription: String {
return makeDescription(isDebug: true)
return _makeCollectionDescription(for: self, withTypeName: "Set")
}
}