@@ -35,8 +35,7 @@ public final class URLQueryEncoder {
3535 /// If the closure fails to encode a value into the given encoder, the encoder will encode an empty automatic container in its place.
3636 case custom( ( Date ) -> String )
3737 }
38-
39- fileprivate( set) var codingPath : [ CodingKey ] = [ ]
38+
4039 public private( set) var queryItems : [ URLQueryItem ] = [ ]
4140
4241 public var items : [ ( String , String ? ) ] {
@@ -67,7 +66,7 @@ public final class URLQueryEncoder {
6766 _delimeter = delimeter ?? self . delimeter
6867 _isDeepObject = isDeepObject ?? self . isDeepObject
6968
70- let encoder = _URLQueryEncoder ( encoder: self , codingPath : codingPath )
69+ let encoder = _URLQueryEncoder ( encoder: self )
7170 do {
7271 try value. encode ( to: encoder)
7372 } catch {
@@ -215,19 +214,19 @@ private extension URLQueryEncoder {
215214
216215private struct _URLQueryEncoder : Encoder {
217216 let encoder : URLQueryEncoder
218- var codingPath : [ CodingKey ]
217+ var codingPath : [ CodingKey ] = [ ]
219218 var userInfo : [ CodingUserInfoKey : Any ] { return [ : ] }
220219
221220 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) )
223222 }
224223
225224 func unkeyedContainer( ) -> UnkeyedEncodingContainer {
226- UnkeyedContanier ( encoder: encoder, codingPath: encoder . codingPath)
225+ UnkeyedContanier ( encoder: encoder, codingPath: codingPath)
227226 }
228227
229228 func singleValueContainer( ) -> SingleValueEncodingContainer {
230- SingleValueContanier ( encoder: encoder, codingPath: encoder . codingPath)
229+ SingleValueContanier ( encoder: encoder, codingPath: codingPath)
231230 }
232231}
233232
@@ -236,17 +235,11 @@ private struct KeyedContainer<Key: CodingKey>: KeyedEncodingContainerProtocol {
236235 let codingPath : [ CodingKey ]
237236
238237 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] )
243239 }
244240
245241 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] )
250243 }
251244
252245 func nestedContainer< NestedKey> ( keyedBy keyType: NestedKey . Type , forKey key: Key ) -> KeyedEncodingContainer < NestedKey > where NestedKey : CodingKey {
@@ -321,7 +314,6 @@ private struct SingleValueContanier: SingleValueEncodingContainer {
321314 }
322315
323316 mutating func encode< T> ( _ value: T ) throws where T : Encodable {
324- encoder. codingPath = self . codingPath
325317 try encoder. encodeEncodable ( value, forKey: codingPath)
326318 }
327319}
0 commit comments