@@ -35,8 +35,7 @@ public final class URLQueryEncoder {
35
35
/// If the closure fails to encode a value into the given encoder, the encoder will encode an empty automatic container in its place.
36
36
case custom( ( Date ) -> String )
37
37
}
38
-
39
- fileprivate( set) var codingPath : [ CodingKey ] = [ ]
38
+
40
39
public private( set) var queryItems : [ URLQueryItem ] = [ ]
41
40
42
41
public var items : [ ( String , String ? ) ] {
@@ -67,7 +66,7 @@ public final class URLQueryEncoder {
67
66
_delimeter = delimeter ?? self . delimeter
68
67
_isDeepObject = isDeepObject ?? self . isDeepObject
69
68
70
- let encoder = _URLQueryEncoder ( encoder: self , codingPath : codingPath )
69
+ let encoder = _URLQueryEncoder ( encoder: self )
71
70
do {
72
71
try value. encode ( to: encoder)
73
72
} catch {
@@ -215,19 +214,19 @@ private extension URLQueryEncoder {
215
214
216
215
private struct _URLQueryEncoder : Encoder {
217
216
let encoder : URLQueryEncoder
218
- var codingPath : [ CodingKey ]
217
+ var codingPath : [ CodingKey ] = [ ]
219
218
var userInfo : [ CodingUserInfoKey : Any ] { return [ : ] }
220
219
221
220
func container< Key> ( keyedBy type: Key . Type ) -> KeyedEncodingContainer < Key > where Key : CodingKey {
222
- KeyedEncodingContainer ( KeyedContainer < Key > ( encoder: encoder, codingPath: encoder . codingPath) )
221
+ KeyedEncodingContainer ( KeyedContainer < Key > ( encoder: encoder, codingPath: codingPath) )
223
222
}
224
223
225
224
func unkeyedContainer( ) -> UnkeyedEncodingContainer {
226
- UnkeyedContanier ( encoder: encoder, codingPath: encoder . codingPath)
225
+ UnkeyedContanier ( encoder: encoder, codingPath: codingPath)
227
226
}
228
227
229
228
func singleValueContainer( ) -> SingleValueEncodingContainer {
230
- SingleValueContanier ( encoder: encoder, codingPath: encoder . codingPath)
229
+ SingleValueContanier ( encoder: encoder, codingPath: codingPath)
231
230
}
232
231
}
233
232
@@ -236,17 +235,11 @@ private struct KeyedContainer<Key: CodingKey>: KeyedEncodingContainerProtocol {
236
235
let codingPath : [ CodingKey ]
237
236
238
237
func encode< T> ( _ value: T , forKey key: Key ) throws where T : Encodable {
239
- let codingPath = self . codingPath + [ key]
240
- encoder. codingPath = codingPath
241
- defer { encoder. codingPath. removeLast ( ) }
242
- try encoder. encodeEncodable ( value, forKey: codingPath)
238
+ try encoder. encodeEncodable ( value, forKey: codingPath + [ key] )
243
239
}
244
240
245
241
func encodeNil( forKey key: Key ) throws {
246
- let codingPath = self . codingPath + [ key]
247
- encoder. codingPath = codingPath
248
- defer { encoder. codingPath. removeLast ( ) }
249
- try encoder. encodeNil ( forKey: codingPath)
242
+ try encoder. encodeNil ( forKey: codingPath + [ key] )
250
243
}
251
244
252
245
func nestedContainer< NestedKey> ( keyedBy keyType: NestedKey . Type , forKey key: Key ) -> KeyedEncodingContainer < NestedKey > where NestedKey : CodingKey {
@@ -321,7 +314,6 @@ private struct SingleValueContanier: SingleValueEncodingContainer {
321
314
}
322
315
323
316
mutating func encode< T> ( _ value: T ) throws where T : Encodable {
324
- encoder. codingPath = self . codingPath
325
317
try encoder. encodeEncodable ( value, forKey: codingPath)
326
318
}
327
319
}
0 commit comments