mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user