Add span-based input and output interfaces#1816
Merged
kperryua merged 1 commit intoswiftlang:experimental/new-codablefrom Mar 16, 2026
Merged
Conversation
t089
reviewed
Mar 13, 2026
| @inlinable | ||
| public func decode<T: CommonDecodable>(_ type: T.Type, from data: Data) throws(CodingError.Decoding) -> T { | ||
| try _decode(type, from: data) { parserDecoder throws(CodingError.Decoding) in | ||
| public func decode<T: CommonDecodable>(_ type: T.Type, from span: Span<UInt8>) throws(CodingError.Decoding) -> T { |
Contributor
Author
There was a problem hiding this comment.
I'm not entirely clear on that TBH. For UTF-8 input, we very clearly are semantically reading individual bytes, which makes Span<UInt8> make more sense to be as input. However, internally we're holding on to it as a RawSpan, because we can use SIMD/SWAR techniques to read multiple bytes at a time.
That said, A) it's more straightforward for clients to get a RawSpan from a Span<UInt8> than to go the other way, and B) eventually I suspect we will need to support other wider Unicode encodings like present-day JSONDecoder does, which means we're no longer processing the input byte-by-byte.
dedb966 to
cf2e842
Compare
Contributor
Author
|
Just the known Windows crash on the tests. @t089, any comments on this? |
2290571
into
swiftlang:experimental/new-codable
36 of 38 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Data interfaces still exist for convenience. They should eventually move to cross-module imports.