Skip to content

[JSON] 5.7 compatibility #2633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ extension JSONDecoding.UnkeyedContainer: UnkeyedDecodingContainer {
}

@inline(__always)
mutating func _getOrThrow() throws -> (index: any CodingKey, value: JSONMapValue) {
mutating func _getOrThrow() throws -> (index: _CodingKey, value: JSONMapValue) {
let idx = currentIndex
guard !isAtEnd else {
throw DecodingError.valueNotFound(
Expand Down Expand Up @@ -1314,3 +1314,40 @@ extension JSONDecoding.UnkeyedContainer: UnkeyedDecodingContainer {
self._currMapIdx = array.startIndex
}
}

// Compatibility shim for SE-0370
#if swift(<5.8)
extension UnsafeMutableBufferPointer {
fileprivate func initialize(
fromContentsOf source: some Collection<Element>
) -> Index {
let count = source.withContiguousStorageIfAvailable {
guard let sourceAddress = $0.baseAddress, !$0.isEmpty else {
return 0
}
precondition(
$0.count <= self.count,
"buffer cannot contain every element from source."
)
baseAddress?.initialize(from: sourceAddress, count: $0.count)
return $0.count
}
if let count {
return startIndex.advanced(by: count)
}

var (iterator, copied) = self.initialize(from: source)
precondition(
iterator.next() == nil,
"buffer cannot contain every element from source."
)
return startIndex.advanced(by: copied)
}

fileprivate func initializeElement(at index: Index, to value: Element) {
precondition(startIndex <= index && index < endIndex)
let p = baseAddress!.advanced(by: index)
p.initialize(to: value)
}
}
#endif