Repository navigation
Add Int128, decimal and ISO 8601 options, and number conversion - #62
Open
letko-dmitry wants to merge 12 commits into
Open
letko-dmitry wants to merge 12 commits into
letko-dmitry wants to merge 12 commits into
Conversation
letko-dmitry
marked this pull request as ready for review
October 5, 2026 15:34
letko-dmitry
marked this pull request as draft
October 5, 2026 15:49
letko-dmitry
force-pushed
the
feature/value-formats
branch
from
October 5, 2026 18:26
7825c0d to
653b284
Compare
letko-dmitry
marked this pull request as ready for review
October 5, 2026 18:34
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.
Builds on #61: the first 7 commits belong to it. One commit per change here, so any of them can be dropped:
NSNumberones are. A dictionary built in Swift holdsIntandDoublevalues, while one fromJSONSerializationholdsNSNumber, so["price": 10]decoded into aDoubleonly in the second case. Conversions stay exact (1.5 into anIntstill fails), and booleans aren't numbers, as inJSONDecoder. The conversion runs only where decoding used to fail, so values of the expected type decode as fast as before.Decimalencodes itself as{exponent, isCompact, isNegative, length, mantissa}, which nothing outside Swift reads, whileJSONEncoderwrites a number.DictionaryEncoder(decimalEncodingStrategy: .number)keeps theDecimalas is.decimalDecodingStrategytakes the set of forms to accept, so data in both forms can be read during a migration. The defaults keep today's behavior. Telling decimals apart costs about 0.5% when encoding.Int128andUInt128. Encoding them threwEncodingError.invalidValuefrom the standard library's default implementation, and decoding failed. The containers keep them as is, like the other integers, without checking any other value for them.ISO8601DateFormatter: about 85 µs to format and 124 µs to parse one date on an M4 Mac. A sharedDate.ISO8601FormatStyletakes 0.15 and 0.4 µs. The output is byte for byte the same (checked on 1.3 million dates) and so are the accepted strings (checked on 600,000)..iso8601(style: .formatStyle)adds the behavior ofJSONEncoderandJSONDecoder: fractions of a second are dropped when encoding and kept when decoding..iso8601keeps working as before.The first change affects observable behavior: values that failed to decode now succeed, and an infinite
Doubledecoded into aFloatreportsdataCorruptedinstead oftypeMismatch. Happy to split it out or drop it.Measured as retired instructions in release builds on an M4, alternating A/B runs; differences within ±0.3% are noise.