Skip to content

Commit 799fb06

Browse files
authored
Merge pull request #1259 from itaiferber/fix-sr-5206-hack
Remove previous hack for SR-5206
2 parents 6d862d6 + 5431208 commit 799fb06

File tree

2 files changed

+8
-39
lines changed

2 files changed

+8
-39
lines changed

Foundation/Data.swift

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,27 +1926,11 @@ extension NSData : _HasCustomAnyHashableRepresentation {
19261926

19271927
extension Data : Codable {
19281928
public init(from decoder: Decoder) throws {
1929-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
1930-
do {
1931-
let singleValueContainer = try decoder.singleValueContainer()
1932-
if let decoder = singleValueContainer as? _JSONDecoder {
1933-
switch decoder.options.dataDecodingStrategy {
1934-
case .deferredToData:
1935-
break /* fall back to default implementation below; this would recurse */
1936-
1937-
default:
1938-
// _JSONDecoder has a hook for Datas; this won't recurse since we're not going to defer back to Data in _JSONDecoder.
1939-
self = try singleValueContainer.decode(Data.self)
1940-
return
1941-
}
1942-
}
1943-
} catch { /* fall back to default implementation below */ }
1944-
19451929
var container = try decoder.unkeyedContainer()
19461930

19471931
// It's more efficient to pre-allocate the buffer if we can.
19481932
if let count = container.count {
1949-
self = Data(count: count)
1933+
self.init(count: count)
19501934

19511935
// Loop only until count, not while !container.isAtEnd, in case count is underestimated (this is misbehavior) and we haven't allocated enough space.
19521936
// We don't want to write past the end of what we allocated.
@@ -1955,7 +1939,7 @@ extension Data : Codable {
19551939
self[i] = byte
19561940
}
19571941
} else {
1958-
self = Data()
1942+
self.init()
19591943
}
19601944

19611945
while !container.isAtEnd {
@@ -1965,21 +1949,6 @@ extension Data : Codable {
19651949
}
19661950

19671951
public func encode(to encoder: Encoder) throws {
1968-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
1969-
// We are allowed to request this container as long as we don't encode anything through it when we need the unkeyed container below.
1970-
var singleValueContainer = encoder.singleValueContainer()
1971-
if let encoder = singleValueContainer as? _JSONEncoder {
1972-
switch encoder.options.dataEncodingStrategy {
1973-
case .deferredToData:
1974-
break /* fall back to default implementation below; this would recurse */
1975-
1976-
default:
1977-
// _JSONEncoder has a hook for Datas; this won't recurse since we're not going to defer back to Data in _JSONEncoder.
1978-
try singleValueContainer.encode(self)
1979-
return
1980-
}
1981-
}
1982-
19831952
var container = encoder.unkeyedContainer()
19841953

19851954
// Since enumerateBytes does not rethrow, we need to catch the error, stow it away, and rethrow if we stopped.

Foundation/JSONEncoder.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ open class JSONEncoder {
101101
open var userInfo: [CodingUserInfoKey : Any] = [:]
102102

103103
/// Options set on the top-level encoder to pass down the encoding hierarchy.
104-
internal struct _Options {
104+
fileprivate struct _Options {
105105
let dateEncodingStrategy: DateEncodingStrategy
106106
let dataEncodingStrategy: DataEncodingStrategy
107107
let nonConformingFloatEncodingStrategy: NonConformingFloatEncodingStrategy
@@ -153,14 +153,14 @@ open class JSONEncoder {
153153

154154
// MARK: - _JSONEncoder
155155

156-
internal class _JSONEncoder : Encoder {
156+
fileprivate class _JSONEncoder : Encoder {
157157
// MARK: Properties
158158

159159
/// The encoder's storage.
160160
fileprivate var storage: _JSONEncodingStorage
161161

162162
/// Options set on the top-level encoder.
163-
internal let options: JSONEncoder._Options
163+
fileprivate let options: JSONEncoder._Options
164164

165165
/// The path to the current point in encoding.
166166
public var codingPath: [CodingKey]
@@ -866,7 +866,7 @@ open class JSONDecoder {
866866
open var userInfo: [CodingUserInfoKey : Any] = [:]
867867

868868
/// Options set on the top-level encoder to pass down the decoding hierarchy.
869-
internal struct _Options {
869+
fileprivate struct _Options {
870870
let dateDecodingStrategy: DateDecodingStrategy
871871
let dataDecodingStrategy: DataDecodingStrategy
872872
let nonConformingFloatDecodingStrategy: NonConformingFloatDecodingStrategy
@@ -904,14 +904,14 @@ open class JSONDecoder {
904904

905905
// MARK: - _JSONDecoder
906906

907-
internal class _JSONDecoder : Decoder {
907+
fileprivate class _JSONDecoder : Decoder {
908908
// MARK: Properties
909909

910910
/// The decoder's storage.
911911
fileprivate var storage: _JSONDecodingStorage
912912

913913
/// Options set on the top-level decoder.
914-
internal let options: JSONDecoder._Options
914+
fileprivate let options: JSONDecoder._Options
915915

916916
/// The path to the current point in encoding.
917917
private(set) public var codingPath: [CodingKey]

0 commit comments

Comments
 (0)