Skip to content

Commit 3631959

Browse files
committed
Changed keyed archive mechanics to unkeyed archive mechanics
1 parent 62f8042 commit 3631959

File tree

2 files changed

+24
-60
lines changed

2 files changed

+24
-60
lines changed

stdlib/public/core/ClosedRange.swift

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -490,28 +490,16 @@ public typealias CountableClosedRange<Bound: Strideable> = ClosedRange<Bound>
490490
where Bound.Stride : SignedInteger
491491

492492
extension ClosedRange: Codable where Bound: Codable {
493-
private enum CodingKeys: String, CodingKey {
494-
case lowerBound = "from"
495-
case upperBound = "through"
496-
}
497-
498493
public init(from decoder: Decoder) throws {
499-
let container = try decoder.container(keyedBy: CodingKeys.self)
500-
let lowerBound = try container.decode(Bound.self, forKey: .lowerBound)
501-
let upperBound = try container.decode(Bound.self, forKey: .upperBound)
502-
guard lowerBound <= upperBound else {
503-
throw DecodingError.dataCorruptedError(
504-
forKey: CodingKeys.upperBound,
505-
in: container,
506-
debugDescription: "upperBound (through) cannot be less than lowerBound (from)"
507-
)
508-
}
494+
var container = try decoder.unkeyedContainer()
495+
let lowerBound = try container.decode(Bound.self)
496+
let upperBound = try container.decode(Bound.self)
509497
self = lowerBound...upperBound
510498
}
511499

512500
public func encode(to encoder: Encoder) throws {
513-
var container = encoder.container(keyedBy: CodingKeys.self)
514-
try container.encode(self.lowerBound, forKey: .lowerBound)
515-
try container.encode(self.upperBound, forKey: .upperBound)
501+
var container = encoder.unkeyedContainer()
502+
try container.encode(self.lowerBound)
503+
try container.encode(self.upperBound)
516504
}
517505
}

stdlib/public/core/Range.swift

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -406,29 +406,17 @@ extension Range: Hashable where Bound: Hashable {
406406
}
407407

408408
extension Range: Codable where Bound: Codable {
409-
private enum CodingKeys: String, CodingKey {
410-
case lowerBound = "from"
411-
case upperBound = "upTo"
412-
}
413-
414409
public init(from decoder: Decoder) throws {
415-
let container = try decoder.container(keyedBy: CodingKeys.self)
416-
let lowerBound = try container.decode(Bound.self, forKey: .lowerBound)
417-
let upperBound = try container.decode(Bound.self, forKey: .upperBound)
418-
guard lowerBound <= upperBound else {
419-
throw DecodingError.dataCorruptedError(
420-
forKey: CodingKeys.upperBound,
421-
in: container,
422-
debugDescription: "upperBound (upTo) cannot be less than lowerBound (from)"
423-
)
424-
}
410+
var container = try decoder.unkeyedContainer()
411+
let lowerBound = try container.decode(Bound.self)
412+
let upperBound = try container.decode(Bound.self)
425413
self = lowerBound..<upperBound
426414
}
427415

428416
public func encode(to encoder: Encoder) throws {
429-
var container = encoder.container(keyedBy: CodingKeys.self)
430-
try container.encode(self.lowerBound, forKey: .lowerBound)
431-
try container.encode(self.upperBound, forKey: .upperBound)
417+
var container = encoder.unkeyedContainer()
418+
try container.encode(self.lowerBound)
419+
try container.encode(self.upperBound)
432420
}
433421
}
434422

@@ -475,18 +463,14 @@ extension PartialRangeUpTo: RangeExpression {
475463
}
476464

477465
extension PartialRangeUpTo: Codable where Bound: Codable {
478-
private enum CodingKeys: String, CodingKey {
479-
case upperBound = "fromStartUpTo"
480-
}
481-
482466
public init(from decoder: Decoder) throws {
483-
let container = try decoder.container(keyedBy: CodingKeys.self)
484-
self = try (..<container.decode(Bound.self, forKey: .upperBound))
467+
var container = try decoder.unkeyedContainer()
468+
self = try (..<container.decode(Bound.self))
485469
}
486470

487471
public func encode(to encoder: Encoder) throws {
488-
var container = encoder.container(keyedBy: CodingKeys.self)
489-
try container.encode(self.upperBound, forKey: .upperBound)
472+
var container = encoder.unkeyedContainer()
473+
try container.encode(self.upperBound)
490474
}
491475
}
492476

@@ -532,18 +516,14 @@ extension PartialRangeThrough: RangeExpression {
532516
}
533517

534518
extension PartialRangeThrough: Codable where Bound: Codable {
535-
private enum CodingKeys: String, CodingKey {
536-
case upperBound = "fromStartThrough"
537-
}
538-
539519
public init(from decoder: Decoder) throws {
540-
let container = try decoder.container(keyedBy: CodingKeys.self)
541-
self = try (...container.decode(Bound.self, forKey: .upperBound))
520+
var container = try decoder.unkeyedContainer()
521+
self = try (...container.decode(Bound.self))
542522
}
543523

544524
public func encode(to encoder: Encoder) throws {
545-
var container = encoder.container(keyedBy: CodingKeys.self)
546-
try container.encode(self.upperBound, forKey: .upperBound)
525+
var container = encoder.unkeyedContainer()
526+
try container.encode(self.upperBound)
547527
}
548528
}
549529

@@ -684,18 +664,14 @@ extension PartialRangeFrom: Sequence
684664
}
685665

686666
extension PartialRangeFrom: Codable where Bound: Codable {
687-
private enum CodingKeys: String, CodingKey {
688-
case lowerBound = "toEndFrom"
689-
}
690-
691667
public init(from decoder: Decoder) throws {
692-
let container = try decoder.container(keyedBy: CodingKeys.self)
693-
self = try container.decode(Bound.self, forKey: .lowerBound)...
668+
var container = try decoder.unkeyedContainer()
669+
self = try container.decode(Bound.self)...
694670
}
695671

696672
public func encode(to encoder: Encoder) throws {
697-
var container = encoder.container(keyedBy: CodingKeys.self)
698-
try container.encode(self.lowerBound, forKey: .lowerBound)
673+
var container = encoder.unkeyedContainer()
674+
try container.encode(self.lowerBound)
699675
}
700676
}
701677

0 commit comments

Comments
 (0)