@@ -151,21 +151,21 @@ final class SharedEncoderData {
151
151
/// Inserts the other autdeallocated storage into this storage
152
152
func insert( contentsOf storage: SharedEncoderData , count: Int , at offset: inout Int ) {
153
153
beforeWrite ( offset: offset, count: count)
154
- self . pointer. advanced ( by: offset) . assign ( from: storage. pointer, count: count)
154
+ self . pointer. advanced ( by: offset) . update ( from: storage. pointer, count: count)
155
155
offset = offset &+ count
156
156
}
157
157
158
158
/// Inserts the other autdeallocated storage into this storage
159
159
func insert( contentsOf data: [ UInt8 ] , at offset: inout Int ) {
160
160
beforeWrite ( offset: offset, count: data. count)
161
- self . pointer. advanced ( by: offset) . assign ( from: data, count: data. count)
161
+ self . pointer. advanced ( by: offset) . update ( from: data, count: data. count)
162
162
offset = offset &+ data. count
163
163
}
164
164
165
165
/// Inserts the other autdeallocated storage into this storage
166
166
func insert( contentsOf storage: StaticString , at offset: inout Int ) {
167
167
beforeWrite ( offset: offset, count: storage. utf8CodeUnitCount)
168
- self . pointer. advanced ( by: offset) . assign ( from: storage. utf8Start, count: storage. utf8CodeUnitCount)
168
+ self . pointer. advanced ( by: offset) . update ( from: storage. utf8Start, count: storage. utf8CodeUnitCount)
169
169
offset = offset &+ storage. utf8CodeUnitCount
170
170
}
171
171
@@ -175,7 +175,7 @@ final class SharedEncoderData {
175
175
let utf8 = string. utf8
176
176
let count = utf8. withContiguousStorageIfAvailable { utf8String -> Int in
177
177
self . beforeWrite ( offset: writeOffset, count: utf8String. count)
178
- self . pointer. advanced ( by: writeOffset) . assign (
178
+ self . pointer. advanced ( by: writeOffset) . update (
179
179
from: utf8String. baseAddress!,
180
180
count: utf8String. count
181
181
)
@@ -187,7 +187,7 @@ final class SharedEncoderData {
187
187
} else {
188
188
let count = utf8. count
189
189
let buffer = Array ( utf8)
190
- self . pointer. advanced ( by: writeOffset) . assign (
190
+ self . pointer. advanced ( by: writeOffset) . update (
191
191
from: buffer,
192
192
count: count
193
193
)
@@ -366,10 +366,14 @@ fileprivate final class _JSONEncoder: Encoder {
366
366
case . deferredToDate:
367
367
return false
368
368
case . secondsSince1970:
369
- key. map { writeKey ( $0) }
369
+ if let key = key {
370
+ writeKey ( key)
371
+ }
370
372
writeValue ( date. timeIntervalSince1970)
371
373
case . millisecondsSince1970:
372
- key. map { writeKey ( $0) }
374
+ if let key = key {
375
+ writeKey ( key)
376
+ }
373
377
writeValue ( date. timeIntervalSince1970 * 1000 )
374
378
case . iso8601:
375
379
let string : String
@@ -384,11 +388,15 @@ fileprivate final class _JSONEncoder: Encoder {
384
388
writeValue ( string)
385
389
case . formatted( let formatter) :
386
390
let string = formatter. string ( from: date)
387
- key. map { writeKey ( $0) }
391
+ if let key = key {
392
+ writeKey ( key)
393
+ }
388
394
writeValue ( string)
389
395
case . custom( let custom) :
390
396
let offsetBeforeKey = offset, hadWrittenValue = didWriteValue
391
- key. map { writeKey ( $0) }
397
+ if let key = key {
398
+ writeKey ( key)
399
+ }
392
400
let encoder = _JSONEncoder ( codingPath: codingPath, userInfo: userInfo, data: self . data)
393
401
try custom ( date, encoder)
394
402
if encoder. didWriteValue {
@@ -409,11 +417,15 @@ fileprivate final class _JSONEncoder: Encoder {
409
417
return false
410
418
case . base64:
411
419
let string = data. base64EncodedString ( )
412
- key. map { writeKey ( $0) }
420
+ if let key = key {
421
+ writeKey ( key)
422
+ }
413
423
writeValue ( string)
414
424
case . custom( let custom) :
415
425
let offsetBeforeKey = offset, hadWrittenValue = didWriteValue
416
- key. map { writeKey ( $0) }
426
+ if let key = key {
427
+ writeKey ( key)
428
+ }
417
429
let encoder = _JSONEncoder ( codingPath: codingPath, userInfo: userInfo, data: self . data)
418
430
try custom ( data, encoder)
419
431
if encoder. didWriteValue {
@@ -427,6 +439,19 @@ fileprivate final class _JSONEncoder: Encoder {
427
439
throw JSONParserError . unknownJSONStrategy
428
440
}
429
441
442
+ return true
443
+ case let url as URL :
444
+ if let key = key {
445
+ writeKey ( key)
446
+ }
447
+ writeValue ( url. absoluteString)
448
+ return true
449
+ case let decimal as Decimal :
450
+ if let key = key {
451
+ writeKey ( key)
452
+ }
453
+ data. insert ( contentsOf: decimal. description, at: & offset)
454
+ didWriteValue = true
430
455
return true
431
456
default :
432
457
return false
@@ -693,3 +718,11 @@ fileprivate struct UnkeyedJSONEncodingContainer: UnkeyedEncodingContainer {
693
718
return _JSONEncoder ( codingPath: codingPath, userInfo: self . encoder. userInfo, data: self . encoder. data)
694
719
}
695
720
}
721
+
722
+ #if swift(<5.8)
723
+ extension UnsafeMutablePointer {
724
+ func update( from buffer: UnsafePointer < Pointer > , count: Int ) {
725
+ self . assign ( from: buffer, count: count)
726
+ }
727
+ }
728
+ #endif
0 commit comments